procedure IconToBitmap(const IcoFile,BmpFile:string); var icon:TIcon; Bitmap:TBitmap; begin try icon:=TIcon.Create; Bitmap:=TBitmap.Create; icon.LoadFromFile(IcoFile); Bitmap.Assign(icon); Bitmap.SaveToFile(BmpFile); finally icon.free; Bitmap.Free; end; end;
转载: var bmp:tbitmap; ic:ticon; begin bmp:=tbitmap.create; try with bmp do begin width:=image1.picture.width; height;=image1.picture.height; canvas.draw(0,0,image1.picture.graphic); image2.picture.assigh(bmp); end; finally bmp.free; end; 主要是调用draw方法。
太easy了,API: GetIconInfo
procedure TForm1.FlatButton1Click(Sender: TObject); var Icon:Ticon; Bitmap:TBitmap; img:String;{设定要保存的.BMP文件名} begin Icon:=TIcon.Create; Bitmap:=TBitmap.Create; if not FileExists(Edit1.Text) then begin Application.MessageBox('您没有选择,或所选择的.ICO文件不存在,请重新选择!','信息',MB_ICONINFORMATION+MB_OK); exit{如果不能打开.ico图像文件则报告错误,并退出,不在进行下面的操作} end else begin if (Edit2.Text='') then begin Application.MessageBox('您没有给这个新的.BMP文件起名,程序将自动为它命名','信息',MB_ICONINFORMATION+MB_OK); {如果发现Edit2的Text属性为空,则则报给出提示信息,但将继续执行} img:=ChangeFileExt(Edit1.Text,'.bmp');{新文件取Eeit1.Text为文件名} end else img:=copy(edit2.text,1,pos('.ico',edit1.text))+'.bmp'; {新文件名取Eeit2的TEXT做为文件名} end; Icon.LoadFromFile(Edit1.Text);{取Edit1的图像文件} Bitmap.Width:=Icon.Width; Bitmap.Height:=Icon.Height; {设ICO囹像的大小} Bitmap.Canvas.Draw(0,0,Icon); Bitmap.SaveToFile(img); {建立新的.BMP文件} Icon.Free; Bitmap.Free; end;
var
icon:TIcon;
Bitmap:TBitmap;
begin
try
icon:=TIcon.Create;
Bitmap:=TBitmap.Create;
icon.LoadFromFile(IcoFile);
Bitmap.Assign(icon);
Bitmap.SaveToFile(BmpFile);
finally
icon.free;
Bitmap.Free;
end;
end;
var
bmp:tbitmap;
ic:ticon;
begin
bmp:=tbitmap.create;
try
with bmp do
begin
width:=image1.picture.width;
height;=image1.picture.height;
canvas.draw(0,0,image1.picture.graphic);
image2.picture.assigh(bmp);
end;
finally
bmp.free;
end;
主要是调用draw方法。
var
Icon:Ticon;
Bitmap:TBitmap;
img:String;{设定要保存的.BMP文件名}
begin
Icon:=TIcon.Create;
Bitmap:=TBitmap.Create;
if not FileExists(Edit1.Text)
then
begin
Application.MessageBox('您没有选择,或所选择的.ICO文件不存在,请重新选择!','信息',MB_ICONINFORMATION+MB_OK);
exit{如果不能打开.ico图像文件则报告错误,并退出,不在进行下面的操作}
end
else
begin
if (Edit2.Text='') then
begin
Application.MessageBox('您没有给这个新的.BMP文件起名,程序将自动为它命名','信息',MB_ICONINFORMATION+MB_OK);
{如果发现Edit2的Text属性为空,则则报给出提示信息,但将继续执行}
img:=ChangeFileExt(Edit1.Text,'.bmp');{新文件取Eeit1.Text为文件名}
end
else
img:=copy(edit2.text,1,pos('.ico',edit1.text))+'.bmp'; {新文件名取Eeit2的TEXT做为文件名}
end;
Icon.LoadFromFile(Edit1.Text);{取Edit1的图像文件}
Bitmap.Width:=Icon.Width;
Bitmap.Height:=Icon.Height; {设ICO囹像的大小}
Bitmap.Canvas.Draw(0,0,Icon);
Bitmap.SaveToFile(img); {建立新的.BMP文件}
Icon.Free;
Bitmap.Free;
end;