如何在delphi中编写并提取exe文件里面的ICO图标

如何在delphi中编写并提取exe文件里面的ICO图标,第1张

提取 exe 文件里面的 ICO 图标,通常可以 WinAPI 函数 ExtractIcon,以下是示例代码:

procedure TForm1RzBitBtn1Click(Sender: TObject);

var iCount: Integer;

begin

  if OpenDialog1Execute then

  begin

    Edit1Text := OpenDialog1FileName;

    iCount := ExtractIcon(HInstance, PChar(OpenDialog1FileName), $FFFFFFFF);

    if iCount>0 then

    begin

      Label2Caption := Format('当前 EXE 文件中共包含 %d 个 ICON 资源。',[iCount]);

      Image1PictureIconHandle := ExtractIcon(HInstance,PChar(OpenDialog1FileName),0);

    end else

    begin

      Label2Caption := '当前 EXE 文件中不包含 ICON 资源。';

    end;

  end;

end;

运行效果截图:

图标小精灵

>

你说的那个我不知道,但我知道有一个可以。

叫 上兴文件捆绑器

里面有提取EXE图标功能

下载地址:>

'SavePicture方法保存ico图标时会失真,他保存真彩色时候会自动把图标转换成256色,这也是这个方法保存ico的不足,除非自己懂ico文件结构,把ico图标数据自己写到文件中,否则该函数会自动将真彩色 转换 256色保存,放在picturebox中的已经不是ico图标了,那是bmp,即使把bmp背景去掉还是要显示出来,ico里面有2张位图,一张是真图,另一张是掩码图(掩码图就是在显示的时候去除真图中不该显示的地方,比如说把ico图标放在桌面显示,系统会将ico的真图和掩码图拿出来,通过掩码图进行一种图像的叠加计算,让真图不该显示的地方去掉,让这个去掉的地方显示桌面的背景图)

Private Type PicBmp

Size As Long

tType As Long

hBmp As Long

hPal As Long

Reserved As Long

End Type

Private Type GUID

Data1 As Long

Data2 As Integer

Data3 As Integer

Data4(7) As Byte

End Type

Private Declare Function ExtractIcon& Lib "shell32dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long)

Private Declare Function OleCreatePictureIndirect Lib "olepro32dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As Picture) As Long

Private Declare Function ExtractIconEx Lib "shell32dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long

Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long

Public Function GetIconFromFile(FileName As String) As Picture

Dim hlargeicon As Long, hsmallicon As Long, selhandle As Long

Dim pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID

selhandle = ExtractIcon(0, FileName, 0)

If selhandle > 0 Then

With IID_IDispatch

Data1 = &H20400

Data4(0) = &HC0

Data4(7) = &H46

End With

With pic

Size = Len(pic)

tType = vbPicTypeIcon

hBmp = selhandle

End With

Call OleCreatePictureIndirect(pic, IID_IDispatch, 0, IPic)

Picture1Picture = IPic

Set GetIconFromFile = IPic

DestroyIcon hsmallicon

DestroyIcon hlargeicon

End If

End Function

Private Sub Form_Load()

SavePicture GetIconFromFile("exe文件路径"), "保存的位置ico"

End Sub

以上就是关于如何在delphi中编写并提取exe文件里面的ICO图标全部的内容,包括:如何在delphi中编写并提取exe文件里面的ICO图标、怎样从.exe文件中提取ICO图标!、EXE图标提取等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10100367.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存