Função para converter Ícone para Bitmap.
É necessário estar declarado Graphics, Windows na seção uses,
em versões unicode declare Vcl.Graphics, Winapi.Windows;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| function IcoToBmp(Icone: TIcon): TBitmap;
var
IconInfo: TIconInfo;
begin
GetIconInfo(Icone.Handle, IconInfo);
Result := TBitmap.Create;
with Result do
begin
PixelFormat := pfDevice;
Width := (IconInfo.xHotspot * 2);
Height := (IconInfo.yHotspot * 2);
Transparent := True;
TransparentMode := tmAuto;
Canvas.StretchDraw(Rect(0, 0, Width, Height), Icone);
end;
end; |
function IcoToBmp(Icone: TIcon): TBitmap;
var
IconInfo: TIconInfo;
begin
GetIconInfo(Icone.Handle, IconInfo);
Result := TBitmap.Create;
with Result do
begin
PixelFormat := pfDevice;
Width := (IconInfo.xHotspot * 2);
Height := (IconInfo.yHotspot * 2);
Transparent := True;
TransparentMode := tmAuto;
Canvas.StretchDraw(Rect(0, 0, Width, Height), Icone);
end;
end;
Exemplo de uso:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| procedure TForm1.Button1Click(Sender: TObject);
var
vBitmap: TBitmap;
vIcon: TIcon;
begin
vIcon := TIcon.Create;
vIcon.LoadFromFile('D:\teste.ico');
vBitmap := IcoToBmp(vIcon);
vBitmap.SaveToFile('D:\teste.bmp');
vIcon.Free;
vBitmap.Free;
end; |
procedure TForm1.Button1Click(Sender: TObject);
var
vBitmap: TBitmap;
vIcon: TIcon;
begin
vIcon := TIcon.Create;
vIcon.LoadFromFile('D:\teste.ico');
vBitmap := IcoToBmp(vIcon);
vBitmap.SaveToFile('D:\teste.bmp');
vIcon.Free;
vBitmap.Free;
end;
-
InfusTec
-
3.177 views
- 0 comentários
- 30 de março de 2015
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo