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-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
追问
这个代码有两个问题:
1."Picture1.Picture = Picture1.Image"这段代码让picture1显示的内容消失了
2.这是我搜的第一个代码,获取的图标很不清楚·
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询