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

Re: [pygame] Saving Alpha Channels



Well, you could try getting the alpha array via
pygame.surfarray.pixels_alpha and then running:
alphas[...] = 128 # Sets all alpha values to 128.

Might have to run it through Surface.convert_alpha before it's got an
alpha array to work with, though.

-FM

On Sat, Oct 4, 2008 at 11:47 PM, Ian Mallett <geometrian@xxxxxxxxx> wrote:
> On Sat, Oct 4, 2008 at 8:51 PM, Brad Montgomery <brad@xxxxxxxxxxxxxxxxxx>
> wrote:
>>
>> Would something like PIL's putalpha do what you want? (provided you *have*
>> PIL)
>
> Yes, I have PIL.
>>
>> http://www.pythonware.com/library/pil/handbook/image.htm (search for
>> putalpha)
>>
>> import Image
>> my_image = Image.open('somefile.jpg')
>> my_image.put_alpha(0)
>> my_image.save('somefile.png')
>>
>> This would convert all the black (int val for black = 0) in your image
>> to alpha's, but then you'd have to save to something that supports an
>> alpha channel.
>>
>> --
>> brad [bradmontgomery.net]
>
> Well, I want to set the alpha value for every pixel.  So, every pixel,
> regardless of its color should be 50% transparent.  The code I posted does
> that, but it doesn't save that alpha data to the file.
> Ian
>