Squall_FF8 0 Posted 9 hours ago Hey guys, I would like to add couple of .png images in an ImageList using design time ImageListEditor. However after I click Add, I get black rectangle? Is this working in Delphi 12? Share this post Link to post
Remy Lebeau 1529 Posted 8 hours ago Standard TImageList does not support PNGs only BMPs. Try TImageCollection+TVirtualImageList instead. Or, there's a 3rd party TPngImageList floating around somewhere. Share this post Link to post
Squall_FF8 0 Posted 7 hours ago 1 hour ago, Remy Lebeau said: Standard TImageList does not support PNGs only BMPs. Try TImageCollection+TVirtualImageList instead. Or, there's a 3rd party TPngImageList floating around somewhere. Thank you for you answer! It is very strange to me, that Delphi doesnt support png. You can add ico, which is like png without compression. I hoped in latest version they will fix this, but alas, no (most likely never, no interest in it). BTW by "floating", are you referring to "PngComponents" accessible trough Getit? Share this post Link to post
Anders Melander 1937 Posted 5 hours ago 1 hour ago, Squall_FF8 said: It is very strange to me, that Delphi doesnt support png. You can add ico, which is like png without compression. You've most like setup your imagelist to use masked transparency (which is probably what your icons are using). 2 hours ago, Squall_FF8 said: I hoped in latest version they will fix this, but alas, no (most likely never, no interest in it). I think they've done their part with regard to this. Now you just need to do your part and read the documentation: https://docwiki.embarcadero.com/Libraries/Sydney/en/API:Vcl.Controls.TImageList.ColorDepth https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.ImgList.TDrawingStyle Share this post Link to post
Remy Lebeau 1529 Posted 5 hours ago (edited) 2 hours ago, Squall_FF8 said: It is very strange to me, that Delphi doesnt support png. You can add ico, which is like png without compression. I didn't say Delphi doesn't support PNG. I said TImageList doesn't support PNG. Internally, TImageList is based on the Win32 IMAGELIST control, which supports only BMP and ICO images. 2 hours ago, Squall_FF8 said: I hoped in latest version they will fix this, but alas, no (most likely never, no interest in it). They can't "fix this" as it is a Win32 limitation. They worked around it (amongst other reasons) by creating TImageCollection and TVirtualImageList to replace the old TImageList: Supporting high-DPI images with the Image Collection and Virtual ImageList components 2 hours ago, Squall_FF8 said: BTW by "floating", are you referring to "PngComponents" accessible trough Getit? Probably, yes. Edited 4 hours ago by Remy Lebeau Share this post Link to post
Squall_FF8 0 Posted 2 hours ago 2 hours ago, Anders Melander said: I think they've done their part with regard to this. Now you just need to do your part and read the documentation: OK, lets do it. From suggested links I used: In order to test it, I used an Image on top of SpeedButton. Image works fine with png. SpedButton is used because it is not WinControl (and thus can be under the image). Also the image overlap the glyph (to prove semi-transparency). Results: The Image (left) works perfectly, but the ImageList (on the right)... kind-a works - its much darker then the original. Did I missed something? Share this post Link to post
Anders Melander 1937 Posted 1 hour ago 28 minutes ago, Squall_FF8 said: Results: The Image (left) works perfectly, but the ImageList (on the right)... kind-a works - its much darker then the original. Did I missed something? AFAIR this is a bug in TPNGImage. I believe it's already been reported but I could be wrong. What happens (and I'm doing this from memory), when you add a PNG to an imagelist (which as Remy pointed out "supports only BMP and ICO" (more on that later)), is that Delphi load the PNG into a TPNGImage, converts it to a 32-bit TBitmap and then adds that bitmap to the imagelist. The bug is that the bitmap TPNGImage produces is premultiplied (all pixel colors have been multiplied with their alpha; pRGB = RGB * A / 255) while the imagelist expects the bitmap to be not-premultiplied, so to say. The result is that you get a semi-transparent 32-bit RGBA bitmap which is too dark. I believe the premultiply problem can be worked around, in code, but I'm too busy to find the solution right now. With regard to imagelist only supporting BMP and ICO: That doesn't really matter in this case. First, let's forget about the ICO support since that is only relevant if you need icons' ability to contain multiple versions (size/color depth/etc) of the same image. That leaves BMP: The imagelist doesn't really contain BMPs which is a file format. It contains DIBs and in the case of a 32-bit imagelist it contains 32-bit DIBs in RGBA format. It doesn't matter if you add a BMP, PNG, JPEG or PCX to the imagelist. Internally it will just store a DIB representation of the image. Share this post Link to post