I'm having an issue with png images in Delphi XE2. I'm leading them using the default TPngImage class and then I'm moving them into a TBitmap32 from Graphics32. This is working fine, but it fails for palette based images which use the tRNS chunk to site transparency. When I use the code provided by GR32 to copy the image, the alpha channel is lost, because those images don't site the alpha channel in the alpha scanline. When I try assigning the palette image is completely lost. Does anyone have any idea how to handle this type of png image in Delphi?

Comments

  1. May be tRNS chunk? It seems Delphi have support for it in PNG.

    ReplyDelete
  2. Yeah, the chunk is supported internally, but it didn't seem to assign it to a bitmap correctly. I have tried to trace down the issue, but I'm seeing some really odd things happening internally that are seemingly unsupported

    ReplyDelete
  3. After going over the PNG specifications and the TPngImage source a couple of times, I've come to a conclusion; There's a bug in TPngImage. The tRNS chunk is handled correctly, but when drawing to another canvas, it forgets to update the alpha channel of the target. As a result, the entire alpha channel is set to 0, makign the bitmap 100% transparent. I'm going to check XE5 when I get home. If it's still in there, I'll report it to the QC. I've modified the source for TPngImage to simply store the alpha value by adding "rgbReserved := TransValue;" in the bugged method and it works perfectly now.

    ReplyDelete
  4. The bug still appears to be there in XE5. Reported as #119399.

    ReplyDelete
  5. Well, I've given up on using TPngImage all together... It should be as easy as assigning the image to a bitmap, but it isn't... I can't get all types of png to work correctly. GR32_PNG and GraphicEx also failed at some point. I'm now combining GR32 with the Vampyre library and it works perfectly.

    ReplyDelete
  6. Open-source can be a silver bullet for Delphi but Embro doesn't interested in it

    ReplyDelete

Post a Comment