Image Alphachannel

Windows specific forum
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Image Alphachannel

Post 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.
Last edited by jamirokwai on Wed Dec 16, 2009 12:29 pm, edited 1 time in total.
Regards,
JamiroKwai
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Image Alphachannel

Post 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.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Image Alphachannel

Post 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
Regards,
JamiroKwai
Post Reply