delphi中如何保存提取的图标
我正在尝试制作图标提取器,
我成功地将图标获取到 image1.picture.icon ,它看起来与原始文件图标相同, 但是当我尝试保存 (iamge1.picture.icon.savetofile(c:\imahe.ico)) 时,
它没有按原样保存,它以较少的颜色保存并且看起来很丑,
请告诉我我做错了什么?
这是我的代码
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Filter:='All files |*.*';
OpenDialog1.Title:='Please select file';
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
szFileName: string;
Icon: TIcon;
SHInfo: TSHFileInfo;
begin
szFileName := Edit1.Text;
if FileExists(Edit1.Text) then
begin
Icon := TIcon.Create;
SHGetFileInfo(PChar(szFileName), 0, SHInfo, SizeOf(SHInfo), SHGFI_ICON);
Icon.Handle := SHInfo.hIcon;
Image1.Picture.Icon := Icon;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Image1.Picture.Icon.SaveToFile(SaveDialog1.FileName+'.ico');
ShowMessage('done');
end;
end;
I am trying to make icon extractor
i am successful in getting icon to image1.picture.icon ,its looking same as orginal file icon,
but when i am trying to save (iamge1.picture.icon.savetofile(c:\imahe.ico))
its not saving as it is ,it saving with less colur and looking ugly
cany any one please tell me what i am doing wrong ?
here is my code
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Filter:='All files |*.*';
OpenDialog1.Title:='Please select file';
if OpenDialog1.Execute then
Edit1.Text:=OpenDialog1.FileName;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
szFileName: string;
Icon: TIcon;
SHInfo: TSHFileInfo;
begin
szFileName := Edit1.Text;
if FileExists(Edit1.Text) then
begin
Icon := TIcon.Create;
SHGetFileInfo(PChar(szFileName), 0, SHInfo, SizeOf(SHInfo), SHGFI_ICON);
Icon.Handle := SHInfo.hIcon;
Image1.Picture.Icon := Icon;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Image1.Picture.Icon.SaveToFile(SaveDialog1.FileName+'.ico');
ShowMessage('done');
end;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SHGetFileInfo 函数有多个标志来获取不同的图标大小。
您可以通过这种方式使用此标志
以获取更多信息,您可以查看此问题的答案。
能否从 Vista 获取 48x48 或 64x64 图标外壳
the SHGetFileInfo function has multiples flags to obtain different icons sizes.
you can use this flags in this way
for more info you can check the answer to this question.
Can 48x48 or 64x64 icons be obtained from the Vista Shell