[ Show ]
[ Shrink ]
Programming and providing support for this service has been a labor
of love since 1997. We are one of the few services online who values our users'
privacy, and have never sold your information. We have even fought hard to defend your
privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket
to continue providing the service. Due to the issues imposed on us by advertisers, we
also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.
Show your support by donating any amount. (Note: We are still technically a for-profit company, so your
contribution is not tax-deductible.)
Donate to VoyForums (PayPal):
[ Next Thread |
Previous Thread |
Next Message |
Previous Message ]
Date Posted: 11:52:30 09/16/03 Tue
Subject: Resource to Bitmap to Icon
I need to display a bitmap 16x16px with 16 colors loaded from an resource as a form icon with correkt tranparency.
I want to use Envision Components only, since I will add later transformations and resized TIFFs.
The resource-stored bitmap use clFuchsia as the transparent color.
First problem is to load the graphic from the resource:
wBmp := TBitmapGraphic.Create;
wStream := TResourceStream.Create(HInstance, aResId, RT_BITMAP);
wBmp.LoadFromStream( wStream );
does not work - I get an exception.
wBmp := TBitmap.Create;
works without a Problem.
Second issue is to Convert to an icon and set it to a TForm.Icon property:
wIco := TIconGraphic.Create;
wIco.Assign( wBmp );
self.Icon := wIco;
This icon has on my system (XP, 1600x1200, large font) lots of unwanted whitespace (clWhite). On an old system (Win95, 640x480, small fonts) it does not (possibly since the system icon size is 16x16). Also the transparent color is not recognized.
Following I found somewhere:
procedure TForm1.BitmapToIcon( const aBmp: TBitmap; const aIcon: TIcon );
aBmp.TransparentColor := clFuchsia;
aBmp.Transparent := true;
with wIconInfo do begin
fIcon := true;
hbmMask := aBmp.MaskHandle;
hbmColor := aBmp.Handle;
wIcon := CreateIconIndirect( wIconInfo );
if wIcon = 0 then
aIcon.Handle := wIcon;
This works better; there is no whitespace, but still the transparency is still not recognized even the Mask seams to be correct; I tested this with
procedure TForm1.DrawMask( aBmp: TBitmap );
wHelp := TBitmap.Create;
wHelp.Handle := aBmp.MaskHandle;
wHelp.Transparent := false;
wBmp := img1.Picture.Bitmap;
wBmp.Width := 100;
wBmp.Height := 100;
wBmp.PixelFormat := pf8bit;
wBmp.HandleType := bmDIB;
wBmp.Canvas.Draw(20, 20, wHelp);
My questions again and explicit:
1. How to load a RT_BITMAP with TBitmapGraphic
2. Hot to convert general a TDibGraphic in 16x16 or 32x32 and 16 to 256 colors to an Icon without whitespace and with correct transparency. A HICON would be sufficient, since I could just set Form1.Icon.Handle to it.
I'm looking for the simplest solution (short and fast code).
Next Thread |
Previous Thread |
Next Message |
[ Contact Forum Admin ]
Forum timezone: GMT-5|
VF Version: 3.00b, ConfDB:
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.