Alpha-blended glyphs for TBitBtn and TSpeedButtons?

I wish to improve the look of my application, so I'm converting all my glyphs from 4 bit per pixel, to (hopefully) 32 bit per pixel with alpha blend.

Unfortunately, it seems I can only use bitmaps as my glyphs, and only 24 bit at best.   Is there some way in Delphi XE8 that I can do proper alpha blending?  I would think a .png file would work great, but it won't let me use a PNG.

I need to do this for both TBitBtn and TSpeedButton.

Thanks!

Carl.
0
Carl
6/10/2015 12:32:46 AM
embarcadero.delphi.graphics 928 articles. 0 followers. Follow

5 Replies
1637 Views

Similar Articles

[PageSpeed] 44

Carl wrote:

> Unfortunately, it seems I can only use bitmaps as my glyphs, and
> only 24 bit at best.   Is there some way in Delphi XE8 that I can
> do proper alpha blending?  I would think a .png file would work
> great, but it won't let me use a PNG.

Standard VCL components, including TBitBtn and TSpeedButton, do not support 
PNG graphics, only BMP graphics (and not alpha-blended BMPs).  There are 
3rd party components that support PNG, though.  For example, I use TPngImageList 
and TPngBitBtn in several of my projects (TPngImageList can even be attached 
to standard VCL components that support TCustomImageList).  But those components 
were made for earlier Delphi versions, I have no clue if they will work in 
modern versions.  You will have to look around.

-- 
Remy Lebeau (TeamB)
1
Remy
6/10/2015 1:06:46 AM
On 10/06/2015 10:32 AM, Carl Olsen wrote:> I wish to improve the look of 
my application, so I'm converting all my glyphs from 4 bit per pixel, to 
(hopefully) 32 bit per pixel with alpha blend.
 >
 > Unfortunately, it seems I can only use bitmaps as my glyphs, and only 
24 bit at best.   Is there some way in Delphi XE8 that I can do proper 
alpha blending?  I would think a .png file would work great, but it 
won't let me use a PNG.
 >
 > I need to do this for both TBitBtn and TSpeedButton.

It's not too hard to do alpha blending  especially onto a monochrome 
background like a button surface. You don't even need to use 
Windows.AlphaBlend (which requires premultiplied alphas).

Here's some code that takes a 32bit bitmap resource, alpha blends it 
with the button's color (clBtnFace) before assigning it to a 
BitBtn.Glyph ...


{$R myBmp.res} //contains a bitmap image resource

type
   PByteArray = ^TByteArray;
   TByteArray = array [0 ..255] of Byte;

   PColorEntry = ^TColorEntry;
   TColorEntry = packed record
     case Integer of
       0: (B, G, R, A: Byte);
       1: (ARGB: Cardinal);
   end;

var
   MulTable: array [Byte, Byte] of Byte;

function Blend(const F, B: Cardinal): Cardinal;
var
   fg: TColorEntry ABSOLUTE F;
   bg: TColorEntry ABSOLUTE B;
   res: TColorEntry ABSOLUTE Result;
   Fw, Bw: PByteArray;
begin
   if fg.A = 0 then result := B
   else if fg.A = $FF then result := F
   else
   begin
     Fw := @MulTable[fg.A];
     Bw := @MulTable[not fg.A];
     Res.R := Fw[fg.R] + Bw[bg.R];
     Res.G := Fw[fg.G] + Bw[bg.G];
     Res.B := Fw[fg.B] + Bw[bg.B];
     Res.A := 255;
   end;
end;

procedure AddBkgndColor(alphaBmp: TBitmap; bkgndColor: Cardinal);
var
   x,y: Integer;
   c: PColorEntry;
   cl: TColorEntry ABSOLUTE bkgndColor;
begin
   alphaBmp.PixelFormat := pf32bit;
   cl.A := 255;
   for y := 0 to alphaBmp.Height -1 do
   begin
     c := alphaBmp.ScanLine[y];
     for x := 0 to alphaBmp.Width -1 do
     begin
       c.ARGB := Blend(c.ARGB, cl.ARGB);
       inc(c);
     end;
   end;
end;

function ColorToRGB32(c: TColor): Cardinal;
begin
   result := Cardinal(ColorToRGB(c));
   //and we also need to swap Red and Blue channels ...
   result := (result and $FF00FF00) or
     ((result shr 16) and $FF) or ((result and $FF) shl 16);
end;

procedure TForm2.FormCreate(Sender: TObject);
var
   bmp: TBitmap;
begin

   //do it all here ...

   bmp := TBitmap.Create;
   try
     bmp.LoadFromResourceID(hInstance, 1);
     AddBkgndColor(bmp, ColorToRGB32(clBtnFace));
     BitBtn1.Glyph.Assign(bmp);
   finally
     bmp.free;
   end;
end;

{$R-}
procedure MakeMulTable;
var
   I, J: Integer;
const
   Div255 = 1 / 255;
begin
   for I := 0 to 255 do MulTable[I, 0] := 0;
   for I := 1 to 255 do
     for J := 0 to 255 do
       MulTable[I, J] := Round(I * J * Div255);
end;
{$R+}

initialization
   MakeMulTable;
0
Angus
6/10/2015 3:18:40 PM
Remy Lebeau (TeamB) wrote:

> But those components were made for
> earlier Delphi versions, I have no clue if they will work in modern
> versions.  You will have to look around.

PngComponents for Delphi 2009 - XE8 are available from CodeCentral:
http://cc.embarcadero.com/Item/26127

-- 
Uwe Raabe
Embarcadero MVP
0
Uwe
6/17/2015 9:53:35 AM
Remy Lebeau (TeamB) wrote:

> But those components were made for
> earlier Delphi versions, I have no clue if they will work in modern
> versions.  You will have to look around.

PngComponents for Delphi 2009 - XE8 are available from CodeCentral:
http://cc.embarcadero.com/Item/26127

-- 
Uwe Raabe
Embarcadero MVP
0
Uwe
6/19/2015 9:24:01 AM
Remy Lebeau (TeamB) wrote:

> But those components were made for
> earlier Delphi versions, I have no clue if they will work in modern
> versions.  You will have to look around.

PngComponents for Delphi 2009 - XE8 are available from CodeCentral:
http://cc.embarcadero.com/Item/26127

-- 
Uwe Raabe
Embarcadero MVP
0
Uwe
6/19/2015 9:25:10 AM
Reply:

Similar Artilces:

Alpha Blend
Hi All. Is there anyway to make the BCB 6 (VCL) controls to Alpha Blend Controls. I want to make it for TImage, TButton. When is moved over it, having a glowing effect. Any ideas grealy appreciated Regards SA Dont know if this helps but I've used a component suite called NextCollection which has support for Alpha blending. They are hands down the best controls I have ever got and not expensive and work with BCB6. Have a look at the demo at http://www.bergsoft.net/ HTH Mike "shaik akbar" <shaikakbar250281@yahoo.co.in> wrote in message news...

alpha blending
I have code that uses ::SetLayeredWindowAttributes() to provide alpha blending of a form. The code works fine for BCB5 to BCB2006, but 2007 and above fails to work when themes are enabled in the project. Is it possible make ::SetLayeredWindowAttributes() function as per earlier versions of C++Builder when themes are enabled ? -- Malcolm Smith MJ Freelancing http://www.mjfreelancing.com Associate Editor C++Builder Developers Journal http://www.bcbjournal.com Malcolm Smith escribió: > I have code that uses ::SetLayeredWindowAttributes() to provide alpha > ...

TBitBtn disabled and glyph
According to the docs, if you have only one glyph, it is used for all states of the button. However I am not finding this to be true. As soon as I set the button state to disabled, even in the designer, the glyph disappears. Am I going to have to work around this (bug?) (documentation error?) by changing my glyph to be twice as wide, a duplicate of itself, and set the number of glyphs to 2? ...

2D graphics for Delphi....
I have another graphics related problem, which is 2D rather than 3D, so I guess GLScene is not a candidate: Say I have a 2D array with XY coordinates and a scalar value in each point. These values vary in some continuous way across the whole XY surface (like barometric pressure across the earth), but the array only contain the (regular or irregular) sampling points. How would I go about color-coding the data so that there is a level map created with one color is designating one pressure range, possibly even with colors gradually changing across the area. Note that there are only so...

Alpha blending in Mozilla.
Hi All, I need some mechanism in Mozilla that will allow me to use 32bit colors in my HTML pages. So, it would be nice to have a color like a #AARRGGBB. I would like to try to implement it by myself. But I need a suggestion. Whether it is possible or not? And if it is possible what classes shuld I hack? Respectfully, Michael. Michael A. Borisov wrote: > Hi All, > > I need some mechanism in Mozilla that will allow me to use 32bit colors > in my HTML pages. So, it would be nice to have a color like a #AARRGGBB. > I would like to try to implement it by myself...

Video alpha blending with html?
Hi, all I'd like to display some html forms in the video with alpha blending. Because of the windows layered transparent window rendered so slow, I can't just lay a transparent window before the video window, it looks really sucks. I've tried uBrowser, it can grab a web page to a target file, and I think it maybe OK for alpha blending with the video via Direct 3D APIs, but I'm not a DirectX developer, who can help me here? Thanks a lot! -- >: ~ ...

3D graphics for Delphi in 2013?
Is it possible for Embarcadero to provide some near future prospects regarding 3D graphic capabilities for Delphi (not firemonkey)? By 3D I do not mean 3-D text or a little 3D triangle structure like the case with Firemonkey... I mean full 3D engine graphics capability usable in _Delphi for Windows PC applications_. To think: We are using fast computers with exciting graphics interface capability and it is _the worst supported aspect of Delphi_. Delphi is currently decades behind time in this regard...and I do not even mention the other standard PC peripherals like audio, mouse, keyboard ...

Problem with PNG graphics in Delphi
I am not a programmer, I am a graphic designer and worked on some images for a program being written in Delphi (I am uncertain of the version). The problem seems to be that no matter what size I create the image, Delphi distorts it and creates what appear to be "holes" in the image that are transparent and show the background color What can we do to fix this issue if anything? Any help would be greatly appreciated. Am 27.03.2010 14:12, schrieb Kristina Thompson: > I am not a programmer, I am a graphic designer and worked on some images for a program being written in Delp...

GD::Graph and alpha blending
Hi all. I've been considering moving our graphing functionality to GD::Graph. I haven't used it at all yet. I read at http://tools.devchannel.org/devtoolschannel/04/04/13/1429242.shtml?tid=29&tid=46 that you can do alpha blending ( which is a requirement ), but I haven't been able to find any examples ( googled, honest ). Has anyone done alpha blending in GD::Graph, in particular inside bars? Seen any example code around? -- Daniel Kasak IT Developer NUS Consulting Group Level 5, 77 Pacific Highway North Sydney, NSW, Australia 2060 T: (+61) 2 9922-7676...

3D graphics library for Delphi?
I am working on a scientific program which needs to visualize 3D body properties. It is supposed to show the properties of the ground after doing a set of measurements and inverting the results. So a block that can be twisted and turned and where the properties are color coded (semi-transparent) is what I am after. We (not myself though) have used GLScene for 2D visualization but for 3D it was done before using VTK and C++ code. But I want to use Delphi since I have 16 years of experience with Object Pascal and basically none with C++... So is it possible to render 3D data as colo...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

TSpeedButton Loosing glyph when disabled
Hi. I have D7. My app is an MDI app. There's a speedbutton on the main form that only appears for two of the 8 children forms. Even in the children forms, there are times when I need to disable the speedbutton. I have a TImageList that holds two separate glyphs. I have two methods that are called to either enable or disable the button. In those methods, I assign the glyph I want for the state I'm going into. The enabled method displays the glyph I want, but the disabled one disappears as soon as I set the enabled property to false. The button appears to be blank when it is d...

Printing alpha-blended images in IE
Another problem that I'm having with printing in IE follows this scenario. I have a base image, and I'm applying "highlite" markups. By this, I literally mean that a section of the base image is covered by a semi-transparent block of color, like you would highlite a piece of paper. I have no problems with semi-transparent images on screen; in fact, I have several successful methods. I can create a DIV with a background color or image. Or I can download a single-pixel GIF or PNG and streach it as large as I need, applying alpha or AlphaImageLoader filters. At any rate, it wo...

Any Perl graphing libraries with alpha blending?
I'm after a Perl graphing library that includes alpha blending support. I've checked out GD::Graph, but it *doesn't* support alpha blending. Are there any options? I know of jpgraph for PHP ( which is excellent for open-source stuff, but the commercial license is too expensive ). -- Daniel Kasak IT Developer NUS Consulting Group Level 5, 77 Pacific Highway North Sydney, NSW, Australia 2060 T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989 email: dkasak@nusconsulting.com.au website: http://www.nusconsulting.com.au Daniel Kasak schreef: > I'm after a Perl grap...

Web resources about - Alpha-blended glyphs for TBitBtn and TSpeedButtons? - embarcadero.delphi.graphics

Accessibility Functionality Add On For Delphi XE6 Firemonkey On Windows And IOS
Fernando Rizzato from Embarcadero has a blog post up with a pretty big add on for Delphi XE6 Firemonkey. The add on is Accessibility functionality ...

Get The Accessibility Support Pack For Delphi XE8 Firemonkey On Windows And Mac OSX
Embarcadero has released a free accessibility pack for Delphi XE8 Firemonkey on Windows and Mac OSX. The accessibility pack brings screen reader ...

Free Accessibility Support Pack For Delphi XE7 Firemonkey On Windows And Mac OSX
Embarcadero has released a free Accessibility pack for Delphi XE7 Firemonkey for Windows and Mac OSX. The accessibility pack brings screen reader ...

Resources last updated: 12/29/2015 8:51:40 PM