我想获取一棵树的图标,用于自制应用程序。有人知道如何提取出图像作为 .icon 文件吗?我需要 16x16 和 32x32 两种尺寸,或者我可以使用屏幕截图。
我想获取一棵树的图标,用于自制应用程序。有人知道如何提取出图像作为 .icon 文件吗?我需要 16x16 和 32x32 两种尺寸,或者我可以使用屏幕截图。
我不能确定自己是否百分百正确,但是根据我的测试,在Windows 10 / 11版本的imageres.dll或shell32.dll上使用7Zip或VS的上述选项似乎不起作用。 这是我看到的内容:
[shell32.dll]
.rsrc\MANIFEST\124
.rsrc\MUI\1
.rsrc\TYPELIB\1
.rsrc\version.txt
.data
.didat
.pdata
.rdata
.reloc
.text
CERTIFICATE
更新:我想我找到原因了。链接到我发现的一篇文章。(抱歉超出领域)。您可以在这些位置的文件中找到资源:
"C:\Windows\SystemResources\shell32.dll.mun"
"C:\Windows\SystemResources\imageres.dll.mun"
Windows 10 1903中imageres.dll中的图标不再存在 - 4kb文件 (来自superuser.com)
shell32.dll
中找到UIFILES
和图标!为什么他们把它们隐藏在.mun
文件中??? - ScienceDiscoverershell32.dll.mun
文件,然后使用 7-Zip 的 Extract Here 功能,找到了我需要的图标。 - Mark Davich另一个选择是使用类似ResourceHacker的工具。它不仅可以处理图标,还有更多功能。干杯!
我需要从shell32.dll中提取图标#238,但不想下载Visual Studio或Resourcehacker,因此我在Technet上找到了一些PowerShell脚本(感谢John Grenfell和这里),这些脚本可以做类似的事情。然后我创建了一个新脚本(如下)以满足我的需求。
我输入的参数是(源DLL路径、目标图标文件名和DLL文件中的图标索引):
C:\Windows\System32\shell32.dll
C:\Temp\Restart.ico
238
我通过临时创建一个新快捷方式(右键单击桌面并选择“新建”-->“快捷方式”,然后键入calc并按两次Enter)进行试错来发现我需要的图标索引是#238。然后右键单击新快捷方式并选择“属性”,然后在“快捷方式”选项卡中单击“更改图标”按钮。粘贴路径C:\Windows\System32\shell32.dll并单击确定。找到你想要使用的图标并计算其索引。注意:索引#2在索引#1下方而不是右侧。我的Windows 7 x64机器上,图标索引#5位于第二列的顶部。
如果有人有类似但获得更高质量图标的更好方法,我会很感兴趣。谢谢,Shaun。
#Windows PowerShell Code###########################################################################
# http://gallery.technet.microsoft.com/scriptcenter/Icon-Exporter-e372fe70
#
# AUTHOR: John Grenfell
#
###########################################################################
<#
.SYNOPSIS
Exports an ico and bmp file from a given source to a given destination
.Description
You need to set the Source and Destination locations. First version of a script, I found other examples but all I wanted to do as grab and ico file from an exe but found getting a bmp useful. Others might find useful
No error checking I'm afraid so make sure your source and destination locations exist!
.EXAMPLE
.\Icon_Exporter.ps1
.Notes
Version HISTORY:
1.1 2012.03.8
#>
Param ( [parameter(Mandatory = $true)][string] $SourceEXEFilePath,
[parameter(Mandatory = $true)][string] $TargetIconFilePath
)
CLS
#"shell32.dll" 238
If ($SourceEXEFilePath.ToLower().Contains(".dll")) {
$IconIndexNo = Read-Host "Enter the icon index: "
$Icon = [System.IconExtractor]::Extract($SourceEXEFilePath, $IconIndexNo, $true)
} Else {
[void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$image = [System.Drawing.Icon]::ExtractAssociatedIcon("$($SourceEXEFilePath)").ToBitmap()
$bitmap = new-object System.Drawing.Bitmap $image
$bitmap.SetResolution(72,72)
$icon = [System.Drawing.Icon]::FromHandle($bitmap.GetHicon())
}
$stream = [System.IO.File]::OpenWrite("$($TargetIconFilePath)")
$icon.save($stream)
$stream.close()
Write-Host "Icon file can be found at $TargetIconFilePath"
Add-Type -AssemblyName System.Drawing
。 - Danny Lo只需使用IrfanView打开DLL文件,然后将结果保存为.gif或.jpg格式。
我知道这个问题已经过时了,但它是从“从dll中提取图标”搜索的第二个谷歌结果,我想避免在我的工作站上安装任何东西,并且我记得我使用IrfanView。
资源提取 是另一款工具,可以递归地从许多 DLL 文件中找到图标,非常方便。
<#
.SYNOPSIS
Exports an ico and bmp file from a given source to a given destination
.Description
You need to set the Source and Destination locations. First version of a script, I found other examples
but all I wanted to do as grab and ico file from an exe but found getting a bmp useful. Others might find useful
.EXAMPLE
This will run but will nag you for input
.\Icon_Exporter.ps1
.EXAMPLE
this will default to shell32.dll automatically for -SourceEXEFilePath
.\Icon_Exporter.ps1 -TargetIconFilePath 'C:\temp\Myicon.ico' -IconIndexNo 238
.EXAMPLE
This will give you a green tree icon (press F5 for windows to refresh Windows explorer)
.\Icon_Exporter.ps1 -SourceEXEFilePath 'C:/Windows/system32/shell32.dll' -TargetIconFilePath 'C:\temp\Myicon.ico' -IconIndexNo 41
.Notes
Based on https://dev59.com/j3VD5IYBdhLWcg3wWKPc Version 1.1 2012.03.8
New version: Version 1.2 2015.11.20 (Added missing custom assembly and some error checking for novices)
#>
Param (
[parameter(Mandatory = $true)]
[string] $SourceEXEFilePath = 'C:/Windows/system32/shell32.dll',
[parameter(Mandatory = $true)]
[string] $TargetIconFilePath,
[parameter(Mandatory = $False)]
[Int32]$IconIndexNo = 0
)
#https://social.technet.microsoft.com/Forums/windowsserver/en-US/16444c7a-ad61-44a7-8c6f-b8d619381a27/using-icons-in-powershell-scripts?forum=winserverpowershell
$code = @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace System
{
public class IconExtractor
{
public static Icon Extract(string file, int number, bool largeIcon)
{
IntPtr large;
IntPtr small;
ExtractIconEx(file, number, out large, out small, 1);
try
{
return Icon.FromHandle(largeIcon ? large : small);
}
catch
{
return null;
}
}
[DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
}
}
"@
If (-not (Test-path -Path $SourceEXEFilePath -ErrorAction SilentlyContinue ) ) {
Throw "Source file [$SourceEXEFilePath] does not exist!"
}
[String]$TargetIconFilefolder = [System.IO.Path]::GetDirectoryName($TargetIconFilePath)
If (-not (Test-path -Path $TargetIconFilefolder -ErrorAction SilentlyContinue ) ) {
Throw "Target folder [$TargetIconFilefolder] does not exist!"
}
Try {
If ($SourceEXEFilePath.ToLower().Contains(".dll")) {
Add-Type -TypeDefinition $code -ReferencedAssemblies System.Drawing
$form = New-Object System.Windows.Forms.Form
$Icon = [System.IconExtractor]::Extract($SourceEXEFilePath, $IconIndexNo, $true)
} Else {
[void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$image = [System.Drawing.Icon]::ExtractAssociatedIcon("$($SourceEXEFilePath)").ToBitmap()
$bitmap = new-object System.Drawing.Bitmap $image
$bitmap.SetResolution(72,72)
$icon = [System.Drawing.Icon]::FromHandle($bitmap.GetHicon())
}
} Catch {
Throw "Error extracting ICO file"
}
Try {
$stream = [System.IO.File]::OpenWrite("$($TargetIconFilePath)")
$icon.save($stream)
$stream.close()
} Catch {
Throw "Error saving ICO file [$TargetIconFilePath]"
}
Write-Host "Icon file can be found at [$TargetIconFilePath]"
还有这个可用的资源,即Visual Studio图像库,它可以“用于创建外观与Microsoft软件视觉上一致的应用程序”,前提是遵循底部给出的许可证。
https://www.microsoft.com/en-ca/download/details.aspx?id=35825