2

I have a DIB handle. How can I convert it to TPNGObject with preserving its transparency?

EDIT : I use method 2 in this solution Here

but the bitmap resulted is not transparent even if i set its Transparent Flag with true

Sara S.
  • 1,365
  • 1
  • 15
  • 33

1 Answers1

1

I think it's going to start out something like this:

var
  lpbi: PBitmapInfoHeader;
begin
  // Get DIB header info from DIB handle
  lpbi := PBitmapInfoHeader(GlobalLock(hdIB));
end;

Then, if it's a 32 bit image, it will have an alpha channel, which you'll use for your transparency data.

Then, you copy the RGB data to the PNG object's scanline and the alpha data to the alpha scanline.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • I use this code to get the bitmap, how can i manipulate it to extract the png image(the bitmap image resulted is not transparent even if i set its Transparent property to true) – Sara S. Nov 28 '11 at 08:21
  • @Sara, yes, the TBitmap only supports a single transparent color, and it's whatever color matches the first pixel (upper left corner). Gustavo Daud's TPNGObject supports a full alpha channel. You use the scanline and alpha scanline properties to copy the data over to, pixel by pixel. – Marcus Adams Nov 28 '11 at 13:44
  • Thanks Marcus but can you help me in how to copy the image data – Sara S. Nov 28 '11 at 13:48