开发者

how to save extracted icon in delphi

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 |*.*'; 
 OpenDial开发者_运维问答og1.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;


the SHGetFileInfo function has multiples flags to obtain different icons sizes.

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.

you can use this flags in this way

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

for more info you can check the answer to this question.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜