Board index » delphi » Bitmap 32->24 Conversion

Bitmap 32->24 Conversion


2008-03-11 02:01:34 AM
delphi18
Hello All,
I am struggling with two procedures to convert a 32bit Bitmap into a 24bit Bitmap.
They look like:
1) procedure Bitmap32To24( SrcBmp, DstBmp: TBitmap; BackgroundColor: TColor );
2) procedure Bitmap32To24( SrcBmp, DstBmp, BckBmp: TBitmap );
The Source Bitmap is a 32-bit ( R + G + B + Alpha channel ) Bitmap.
The Destination Bitmap is a 24-bit ( R + G + B ) Bitmap.
The DstBitmap (24bit) is the result of:
procedure (1) the 32b Bitmap has to be drawn over a solid colored background.
procedure (2) the 32b Bitmap has to be drawn over a background bitmap (24b) of the same size.
Is there anyone who can push me in a good direction?
 
 

Re:Bitmap 32->24 Conversion

<Rob>writes news:47d5777b$XXXX@XXXXX.COM...
Quote
I am struggling with two procedures to convert a 32bit Bitmap into a 24bit
Bitmap.
Its not clear what it is you are looking for.
In general, you dont have to 'convert' a 32bpp to a 24bpp bitmap. Typically
both use 4 bytes per pixel. A 32bit bmp just uses the spare byte to store
the alpha component. In fact, TBitmaps cant load the alpha component for
32bit bitmap, so by default any 32bit bmp loaded using TBitmap gets
'converted' automatically.
If you want to draw the 32bpp bmp using the alpha channel, look at the
AlphaBlend() windows api function, or use a similar function from an
external graphics library.
If this isnt it, please describe what you are trying to do.
 

Re:Bitmap 32->24 Conversion

Quote
In general, you dont have to 'convert' a 32bpp to a 24bpp bitmap. Typically
both use 4 bytes per pixel.
That's not quite true. 24bpp bitmaps use 3 bytes per pixel. 32bpp
bitmaps use 4 bytes, where 1 byte either contains alpha information or
is unused. In the latter case such a bitmap equals a 24bpp bitmap, but
some operations can be done faster because of 32 bit alignment.
Converting a 32bpp bitmap to a 24bpp bitmap can simply be done by
adjusting the PixelFormat property. But I guess that is not what the OP
wants. If Windows 95 support is not required the AlphaBlend function
(see msdn2.microsoft.com/en-us/library/ms532324.aspx) indeed can
be used.
--
Jens Gruschel
www.pegtop.net
 

Re:Bitmap 32->24 Conversion

Jens Gruschel writes:
Quote
>In general, you dont have to 'convert' a 32bpp to a 24bpp bitmap.
>Typically both use 4 bytes per pixel.

That's not quite true. 24bpp bitmaps use 3 bytes per pixel. 32bpp
bitmaps use 4 bytes, where 1 byte either contains alpha information or
is unused. In the latter case such a bitmap equals a 24bpp bitmap, but
some operations can be done faster because of 32 bit alignment.

Converting a 32bpp bitmap to a 24bpp bitmap can simply be done by
adjusting the PixelFormat property. But I guess that is not what the OP
wants. If Windows 95 support is not required the AlphaBlend function
(see msdn2.microsoft.com/en-us/library/ms532324.aspx) indeed can
be used.


i will have a look at (msdn2.microsoft.com/en-us/library/ms532324.aspx).
Windows support for Win95 is indeed not required.
The reason I need these procedures is that I have a collection of button graphics that I want to use
in my own programs. These buttons are 32-bit bitmaps with an alpha channel that is used to anti
alias the graphic around the edges, or to show a shadow around them. Because the ImageList component
of Delphi does not support 32-bit bitmaps, I like to create 24-bit graphics during startup of my
programs and put them into the ImageList. Because different programs may have different background
colors or different background bitmaps I am looking for these two generic procedures that will do the
job for me.
Both GrandmasterB and Jens thank you for your comments.
 

Re:Bitmap 32->24 Conversion

Quote
The reason I need these procedures is that I have a collection of button
graphics that I want to use in my own programs. These buttons are 32-bit
bitmaps with an alpha channel that is used to anti alias the graphic
around the edges, or to show a shadow around them.
Why didn't you say that earlier? ;) Take a look at PngComponents (see
www.thany.org/article/18/VCL), it includes an image list
supporting bitmaps with alpha channel (requires png files).
--
Jens Gruschel
www.pegtop.net