procedure ConvertIconToBitmap( IcoFile,BmpFile : string );
var
Icon1 : TIcon;
Bitmap1 : TBitmap;
begin
Icon1 := TIcon.Create;
Icon1.LoadFromFile(IcoFile);
Bitmap1 := TBitmap.Create;
Bitmap1.Height := Icon1.Height;
Bitmap1.Width := Icon1.Width;
Bitmap1.Canvas.Draw(0, 0, Icon1);
Bitmap1.SaveToFile(BmpFile);
Bitmap1.Free;
Icon1.Free;
end;
--------------------------------------------------------------------
function BitmapToIcon(Bitmap: TBitmap): TIcon;
var
IconSizeX, IconSizeY : integer;
IconInfo: TIconInfo;
IconBitmap, MaskBitmap: TBitmap;
x, y: Integer;
TransparentColor: TColor;
begin
IconSizeX := GetSystemMetrics(SM_CXICON);
IconSizeY := GetSystemMetrics(SM_CYICON);
IconBitmap:= TBitmap.Create;
IconBitmap.Width:= IconSizeX;
IconBitmap.Height:= IconSizeY;
IconBitmap.Canvas.StretchDraw(Rect(0, 0, IconSizeX, IconSizeY), Bitmap);
IconBitmap.TransparentColor:= Bitmap.TransparentColor;
TransparentColor:= IconBitmap.TransparentColor and $FFFFFF;
MaskBitmap:= TBitmap.Create;
MaskBitmap.Assign(IconBitmap);
for y:= 0 to IconSizeY - 1 do
for x:= 0 to IconSizeX - 1 do
if IconBitmap.Canvas.Pixels[x, y] = TransparentColor then
IconBitmap.Canvas.Pixels[x, y]:= clBlack;
IconInfo.fIcon:= True;
IconInfo.hbmMask:= MaskBitmap.MaskHandle;
IconInfo.hbmColor:= IconBitmap.Handle;
Result:= TIcon.Create;
Result.Handle:= CreateIconIndirect(IconInfo);
MaskBitmap.Free;
IconBitmap.Free;
end;