2010-03-20 3 views
1

Je suis en train de faire l'icône extracteurcomment enregistrer l'icône extraite dans delphi

je réussis à obtenir icône image1.picture.icon, sa recherche même que l'icône de fichier orginal, mais quand je suis en train de sauver (iamge1.picture.icon.savetofile (c: \ imahe.ico))

son économie non pas comme il est, il économise avec moins colur et en regardant laid

Cany une s'il vous plaît me dire ce que je fais faux ?

voici mon 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; 

Répondre

1

la fonction SHGetFileInfo a de multiples drapeaux pour obtenir des tailles différentes icônes.

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. 

vous pouvez utiliser ces drapeaux de cette façon

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

pour plus d'informations vous pouvez vérifier la réponse à cette question.

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

+0

merci beaucoup pour le code :) Monsieur – radick

+0

@radick, pas de problème;) – RRUZ

+0

Je me demande pourquoi ce code ne fonctionne pas pour moi voici comment j'utilise procédure TForm1.Button4Click (Sender: TObject); var hicon: TIcon; commencer hicon: = TIcon.Create; essayez GetIconFromFile (Edit1.Text, hicon, SHIL_JUMBO); Image1.Picture.Icon.Assign (hIcon); // affecter à timage enfin hIcon.Free; fin; fin; , mais rien ne se passe lorsque vous cliquez dessus :( – radick

Questions connexes