tags:

views:

212

answers:

1

hi all

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;
+1  A: 

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

RRUZ
thanks alot for code sir :)
radick
@radick, no problem ;)
RRUZ
i wonder why this code not working for me here is how i use procedure TForm1.Button4Click(Sender: TObject);var hicon :TIcon;begin hicon:= TIcon.Create; try GetIconFromFile(Edit1.Text,hicon,SHIL_JUMBO); Image1.Picture.Icon.Assign(hIcon); //assign to timage finally hIcon.Free; end;end;but nothing happens when clicked :(
radick
@radick, you must use the flags in this way `SHGetFileInfo(PChar(szFileName), 0, SHInfo, SizeOf(SHInfo), SHGFI_ICON OR SHIL_LARGE );`
RRUZ
thanks for reply again but it still saving some odd image on to my computer :(but on my application form it looks like so beautiful :) ,but i am not getting why its saving like this :(
radick