Page 1 of 1

Image Alphachannel

Posted: Tue Dec 15, 2009 11:20 am
by jamirokwai
Dear board,

today I tried to figure out how to add an Alphachannel to a JPG-Image. Means: transforming from 24 to 32Bits, I suppose. I don't like API-Calls, if not needed.

This is the code-fragment which did the trick.

Code: Select all

 CreateImage(999,ImageWidth(ToImage),ImageHeight(ToImage),32)
 StartDrawing(ImageOutput(999))
  DrawAlphaImage(ImageID(ToImage), 0, 0, 255)  
 StopDrawing()
 CopyImage(999,ToImage)
Is there a better way using non-api-calls (read: cross-plattform) to change depth of an image?? Maybe one little PB-function?
On Mac OS, the PB-routines draw alpha-channels on not-alphachannelled-jpeg-images, so I wondered why Windows doesn't.

Oh: using Windows XP.

EDIT: corrected the code. Should work now, as said.

Re: Image Alphachannel

Posted: Tue Dec 15, 2009 11:30 am
by blueznl
I fear I cannot resit the urge :-)

http://www.xs4all.nl/~bluez/purebasic/p ... ha_channel

You were on the right track though. On Windows you need to create a 32 bits image otherwise you do not have an alpha channel, and as the alpha channel is by default set to 255, you have to overdraw it with 0 to make it fully transparent.

Re: Image Alphachannel

Posted: Tue Dec 15, 2009 12:55 pm
by jamirokwai
blueznl wrote:I fear I cannot resit the urge :-)

http://www.xs4all.nl/~bluez/purebasic/p ... ha_channel

You were on the right track though. On Windows you need to create a 32 bits image otherwise you do not have an alpha channel, and as the alpha channel is by default set to 255, you have to overdraw it with 0 to make it fully transparent.
Thanks a bunch, blueznl, for the explanation. So I think, my approach is at least a possible solution :)
Just wondering, why Mac OS X doesn't need the conversion? I assume, Mac OS X-Desktops are 32bit by default!?

For your information: I needed this for a small tool... See here: http://www.quadworks.de/?ln=en&app=5
And while researching the possibilities, I found some code about round-edges in the CodeArchive. *doh!*

Going to submit a feature-request, now... :P