Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A button control and underlying replacement for TBitmap that properly handles PNG transparency without writing pre-blend code

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

like image 377
Warren P Avatar asked Aug 23 '11 15:08

Warren P


3 Answers

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

like image 178
Uwe Raabe Avatar answered Nov 14 '22 23:11

Uwe Raabe


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

Link to site...

like image 20
Shambhala Avatar answered Nov 14 '22 23:11

Shambhala


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

like image 2
Warren P Avatar answered Nov 14 '22 23:11

Warren P