Saving an image without alpha channel?

575 views
Skip to first unread message

PhilipBober

unread,
Sep 18, 2007, 7:25:32 AM9/18/07
to pyglet-users
I'm trying to save a screenshot of my program, and I don't want it to
include the alpha channel (This makes it appear different from what my
program looks like when running)
I'm currently using:

image.get_buffer_manager().get_color_buffer().save('out.png')

but it saves the alpha channel. I tried switching it to .BMP (since
that format doesn't support an alpha channel) but pyglet refuses to
write a BMP from RGBA data.
How can I easily drop the alpha channel from the image? I've tried
several things with the image classes but I can't seem to figure this
out.

Alex Holkner

unread,
Sep 18, 2007, 7:37:13 AM9/18/07
to pyglet...@googlegroups.com
PhilipBober wrote:
> I'm trying to save a screenshot of my program, and I don't want it to
> include the alpha channel (This makes it appear different from what my
> program looks like when running)
> I'm currently using:
>
> image.get_buffer_manager().get_color_buffer().save('out.png')
>
> but it saves the alpha channel. I tried switching it to .BMP (since
> that format doesn't support an alpha channel) but pyglet refuses to
> write a BMP from RGBA data.
>
Unless you have PIL, pyglet won't write BMP at all (If you have PIL,
that's what's complaining, not pyglet).

> How can I easily drop the alpha channel from the image? I've tried
> several things with the image classes but I can't seem to figure this
> out.
>

Use the ImageData class to reformat the image. Something like (untested)::

img = image.get_buffer_manager().get_color_buffer().image_data
img.format = 'RGB'
img.save('out.png')

Alex.

PhilipBober

unread,
Sep 18, 2007, 7:44:19 AM9/18/07
to pyglet-users
That works perfectly (and is a way too obvious for how long I spent
messing with it), thanks
Reply all
Reply to author
Forward
0 new messages