vb提取exe图标
我查到的代码提取的图标都不清楚,怎样提取高清图标?保存图标时相当于截图,怎样只是保存图标,去掉那个底?注:我要的是代码,不是他人做好的程序。本人初学,要是讲解一下代码就更...
我查到的代码提取的图标都不清楚,怎样提取高清图标?
保存图标时相当于截图,怎样只是保存图标,去掉那个底?
注:我要的是代码,不是他人做好的程序。本人初学,要是讲解一下代码就更好了 展开
保存图标时相当于截图,怎样只是保存图标,去掉那个底?
注:我要的是代码,不是他人做好的程序。本人初学,要是讲解一下代码就更好了 展开
2个回答
展开全部
'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 "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long)
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As Picture) As Long
Private Declare Function ExtractIconEx Lib "shell32.dll" 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)
Picture1.Picture = IPic
Set GetIconFromFile = IPic
DestroyIcon hsmallicon
DestroyIcon hlargeicon
End If
End Function
Private Sub Form_Load()
SavePicture GetIconFromFile("exe文件路径"), "保存的位置.ico"
End Sub
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 "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long)
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As Picture) As Long
Private Declare Function ExtractIconEx Lib "shell32.dll" 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)
Picture1.Picture = IPic
Set GetIconFromFile = IPic
DestroyIcon hsmallicon
DestroyIcon hlargeicon
End If
End Function
Private Sub Form_Load()
SavePicture GetIconFromFile("exe文件路径"), "保存的位置.ico"
End Sub
博思aippt
2024-07-20 广告
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景。ai生...
点击进入详情页
本回答由博思aippt提供
展开全部
追问
这个代码有两个问题:
1."Picture1.Picture = Picture1.Image"这段代码让picture1显示的内容消失了
2.这是我搜的第一个代码,获取的图标很不清楚·
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询