如何在delphi中保存提取的图标

时间:2010-03-20 03:06:39

标签: delphi save icons

我正在尝试制作图标提取器

我成功获取了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;

1 个答案:

答案 0 :(得分:1)

SHGetFileInfo函数具有多个标记以获得不同的图标大小。

const
  SHIL_LARGE     = $00;  //The image size is normally 32x32 pixels. However, if the Use large icons option is selected from the Effects section of the Appearance tab in Display Properties, the image is 48x48 pixels.
  SHIL_SMALL     = $01;  //These images are the Shell standard small icon size of 16x16, but the size can be customized by the user.
  SHIL_EXTRALARGE= $02;  //These images are the Shell standard extra-large icon size. This is typically 48x48, but the size can be customized by the user.
  SHIL_SYSSMALL  = $03;  //These images are the size specified by GetSystemMetrics called with SM_CXSMICON and GetSystemMetrics called with SM_CYSMICON.
  SHIL_JUMBO     = $04;  //Windows Vista and later. The image is normally 256x256 pixels.

你可以用这种方式使用这个标志

SHGetFileInfo(PChar(szFileName), 0, SHInfo, SizeOf(SHInfo), SHGFI_ICON OR  SHIL_LARGE );

有关详细信息,您可以查看此问题的答案。

Can 48x48 or 64x64 icons be obtained from the Vista Shell