16
votes

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

3
If you don't want to put images in the dfm then don't, load them as resources. This is the only sensible approach in my view. If you put your assets in the dfm files then you lose the ability to keep the assets in revision control.David Heffernan
Why don't you put your PNGs into .ico files and load them into an image list at runtime?David Heffernan
P.S. Hope the new job is working out for you!David Heffernan
TToolBar buttons with an image list should work, too.Ondrej Kelle

3 Answers

12
votes

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

2
votes

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

Link to site...

2
votes

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