16

Delphi 2010's TSpeedButtons did not seem to really support PNG transparency properly, because the Glyph property uses a TBitmap internally, and TBitmap is for bitmaps, and doesn't support PNG transparency properly, and TSpeedButton.Glyph can't support transparency then.. update: But the actual problem was that I had some external stuff (Developer Express components) that was rendering delphi's PNG support non-functional, TImage on the other hand, while it still TPicture, and can support PNG, was also affected by this Developer express bug.

A question was already asked about here, and the answer shows how to use pre-blending so that transparency won't turn into black pixels. I want to know if there is another button control that will use alpha-blended PNGs loaded at designtime, and which does not convert the PNG resources into BMP format discarding the alpha channel and, causing the black border shown here.

In short, this control would not use TBitmap, and would not use the color key transparency feature that is all TBitmap has.

To repeat, I am not asking how to solve the black-around-the-outside issue while still using the out-of-date TBitmap/TSpeedButton based VCL functionality, because it lacks modern PNG transparency functionality, I am asking about replacing it with something else that "just works".

As a secondary drawback, converting a small .png file into a .DFM bitmap resource is essentially wasting space and making my form .DFM content too large. Native .png file format storage within the .dfm should make the resulting forms smaller.

enter image description here

Update: PngComponents look like they should work, but I got an Invalid Graphic format error when I try to load a png into the Png speedbutton. Note that the Png image list component has no such problems. It seems that cxLibrary (a developer express package) is breaking things. Once I removed all developer express stuff, this problem goes away. So although I have selected Pngcomponents as the answer, if you have devex stuff installed, use their buttons instead, and not pngcomponents.

enter image description here

Community
  • 1
  • 1
Warren P
  • 65,725
  • 40
  • 181
  • 316

3 Answers3

12

You may have a look at PngComponents. It has a TPngSpeedbutton and some other controls working directly with PngImages.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • Thanks. Looks good! I think I had heard of them before but never checked them out. – Warren P Aug 23 '11 at 16:20
  • 1
    I had a problem getting .PNGs to load at designtime with PngComponents, and tracked it to an old RXLIB designtime package, which I removed. Now I get Invalid Graphic format exception: [2108C8A0]{designide150.bpl} PicEdit.TGraphicProperty.Edit (Line 272, "PicEdit.pas" + 10) + $12 – Warren P Aug 24 '11 at 20:57
  • confirmed. Developer Express cxLibraryD15 breaks PngComponents. Removed devex stuff from my ide (we don't use it anymore) and no problem. but since lots of people do use it, I'm leaving the note above in the question. It seems that if you use developer express components, the easiest solution is their own cxButton. – Warren P Aug 24 '11 at 21:09
  • PngComponents registers the old TPngObject class in the initialization section of PngFunctions.pas. This will allow loading older forms made with the old PngImage implementation. Other libraries may be doing something similar, which might be the cause of the crash. As I have no DevExpress components at hand in the moment, I cannot figure that out by myself. – Uwe Raabe Aug 24 '11 at 21:39
  • I haven't had DevExpress and still had this error. I have only CnWizards and GExperts. The only way I managed to get rid of the error was to associate explicitly with 'PNG' extension in PngFunctions.pas like this: "TPicture.RegisterFileFormat('PNG', 'PNG File', TPNGObject);" – Nedko Sep 16 '14 at 15:55
2

You could also look into the TMS Software Component called TAdvGlowButton as this supports PNG images with alpha transparency.

Link to site...

Shambhala
  • 1,159
  • 3
  • 13
  • 31
2

It turns out that cxButton that comes in the Developer Express VCL component pack also supports PNG buttons.

Warren P
  • 65,725
  • 40
  • 181
  • 316