2

I have a PNG (32-bit) image in a TImage. A form has a Glass Frame. Picture's background is black, not transparent. How to fix it?

Delphi 2010.

Thanks.

maxfax
  • 4,281
  • 12
  • 74
  • 120
  • Are you sure which the background of your png image is transparent? – RRUZ Jul 21 '11 at 05:14
  • 1
    sure:) It is even transparent on a not glass form. – maxfax Jul 21 '11 at 05:46
  • Interesting. I just did the same thing here, put a TImage on a form set to SheetOfGlass, added a 32bit PNG with a transparent background (generated out of Fireworks) and it worked fine. Have you tried another image to see if there is something wrong with with the one you are using? – Nat Jul 22 '11 at 09:01
  • May be it is because of the third party component - Alpha Controls... And I have Jedi. – maxfax Jul 22 '11 at 23:15

2 Answers2

7

As workaround you can change the bits of your png image to 32.

Check this sample

the left image is a PNG of 8 bits and the other is of 32 bits.

enter image description here

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • I thought likewise! I tried to change bits in Photoshop CS5 but it saves only in 4 formats and not in PNG. How can I make 32 bits? – maxfax Jul 21 '11 at 17:06
  • a 32-bit picture does not help (I have converted in Paint.net). Still black. What else do you do? – maxfax Jul 21 '11 at 20:21
  • I never has problems with 32 bpp png images, maybe you are doing something wrong try uploading the image with your have problems in a site like http://imgur.com/ (also check this image in your TImage component http://i.imgur.com/a6neJ.png) – RRUZ Jul 21 '11 at 20:37
  • The same, even with your image. I see that your image is 32-bit. I have Delphi 2010. – maxfax Jul 21 '11 at 20:43
  • that is weird. Are you modifying some property of the TImage? are you loading the image in runtime or in design time? – RRUZ Jul 21 '11 at 20:47
  • I create a new project. Then I put TImage, set a picture property to my 32-big PNG image. And then I set SheetOfGlass and Enable to true in a GlassFrame property of a form. – maxfax Jul 21 '11 at 20:55
  • try this TPngImage(Image1.Picture.Graphic).CreateAlpha; – RRUZ Jul 21 '11 at 21:04
  • did you try it on Delphi2010? I have 2010. – maxfax Jul 21 '11 at 21:19
0

You should forget about the TImage as it won't handle the blit right. You need to use GDI+ to manually draw the image on your form. That's only because of the "glass". IF you leave it up the the TImage (or actually the TGraphic displayed in it!), the "background" (glass) will be copied into memory and onto that, a transparant graphic (png?) will be composed, and blitted back tot he form. Unfortunately, the "background" (the glass) will turn out to be black when you blt it back.

So, use GDI+ (google it) and blt using the bitmap.handle. Make sure the bitmap is transparent (i.e. 32bits and the appropriate properties set).

Same with fonts on glass, btw. You have to draw stuff yourself (maybe from a custom component?). You can find a few components that do this already, though... Like http://development.mwcs.de/glowlabel.html.

DDS
  • 4,325
  • 22
  • 33