[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Alpha channels and per pixel alpha



works here

import pygame
import os
def load_alpha_image(name):

    #fullname = os.path.join( 'Images', name)
    fullname = 'default_alpha2.png'

    try:
        image = pygame.image.load(fullname).convert_alpha()
    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit, message
    return image

screen = pygame.display.set_mode((22,22,))
i = load_alpha_image('s')

print i.get_at((0,0))






Results in (0,0,0,0) which is correct for the image given.  What do you get?





On Thu, Jun 11, 2009 at 4:39 PM, Bjorn Samuelsson<bjorn_sam@xxxxxxxxxxx> wrote:
> Here's the image and code:
>
>
> def
>
> load_alpha_image(name):
>
>     fullname = os.path.join(
>
> 'Images', name)
>
>     try:
>
>         image = pygame.image.load(fullname).convert_alpha()
>
>     except pygame.error, message:
>
>         print 'Cannot load image:', fullname
>
>         raise SystemExit, message     return image
>
>
> ________________________________
> Date: Wed, 10 Jun 2009 15:56:10 -0700
> Subject: Re: [pygame] Alpha channels and per pixel alpha
> From: brian@xxxxxxxxxxxxxxxxxxx
> To: pygame-users@xxxxxxxx
>
> It would help to see your code and have an example image attached, cause
> loading .png's with alpha and blitting with transparency works fine for me
> without any trouble or special stuff.
>
> On Wed, Jun 10, 2009 at 2:11 PM, Bjorn Samuelsson <bjorn_sam@xxxxxxxxxxx>
> wrote:
>
> Hey all,
>
> I'm trying to make a small 2d game and I'm wondering how you would go about
> to load a png-image with an alpha channel and keep it's alpha values?
> I have confirmed the images alpha channel but when i load it in pygame it's
> alpha values are always 255.
> I've tried Surface.convert_alpha but that doesn't make a difference.
> At the moment I've resorted to saving my alpha channels separate and loading
> both image and alpha channel so that i can call Surface.set_at to change the
> image's per pixel alpha value.
> But that solution seems less than optimal so i figured i would ask you guys.
>
> regards
> Björn
>
> ps. I apologize if this topic has been discussed at length already but i've
> been looking around and i just can't seem to find a simple solution. ds.
>
> ________________________________
> Invite your mail contacts to join your friends list with Windows Live
> Spaces. It's easy! Try it!
>
> ________________________________
> Windows Live™: Keep your life in sync. Check it out!