我想获得树图标用于本土应用程序。有谁知道如何将图像提取为 .icon 文件?我想要 16x16 和 32x32,或者我只是进行屏幕截图。

有帮助吗?

解决方案

在 Visual Studio 中,选择“文件打开...”,然后选择“文件...”。然后选择Shell32.dll。应打开文件夹树,您将在“图标”文件夹中找到图标。

要保存图标,您可以右键单击文件夹树中的图标并选择“导出”。

其他提示

如果有人正在寻找简单的方法,只需使用 7zip 解压缩 shell32.dll 并查找文件夹 .src/ICON/

另一种选择是使用诸如 资源黑客. 。它处理的不仅仅是图标。干杯!

我需要从 shell32.dll 中提取图标 #238,并且不想下载 Visual Studio 或 Resourcehacker,因此我从 Technet 找到了几个 PowerShell 脚本(感谢 John Grenfell 和 #https://social.technet.microsoft.com/Forums/windowsserver/en-US/16444c7a-ad61-44a7-8c6f-b8d619381a27/using-icons-in-powershell-scripts?forum=winserverpowershell)做了类似的事情并创建了一个新脚本(如下)来满足我的需要。

我输入的参数是(源 DLL 路径、目标图标文件名和 DLL 文件内的图标索引):

C:\Windows\System32\shell32.dll

C: emp estart.ico

238

通过临时创建一个新的快捷方式(右键单击桌面并选择新建 --> 快捷方式并输入 calc 并按 Enter 两次),我发现我需要的图标索引是 #238。然后右键单击新快捷方式并选择“属性”,然后单击“快捷方式”选项卡中的“更改图标”按钮。粘贴到路径 C:\Windows\System32\shell32.dll 中,然后单击“确定”。找到您想要使用的图标并计算出其索引。注意:索引#2 位于#1 下方,而不是在其右侧。图标索引 #5 位于我的 Windows 7 x64 计算机上第二列的顶部。

如果有人有更好的方法,其工作原理类似但获得更高质量的图标,那么我有兴趣听到它。谢谢,肖恩。

#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"

资源摘录 是另一个可以从大量 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 http://stackoverflow.com/questions/8435/how-do-you-get-the-icons-out-of-shell32-dll 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]"

只需使用 IrfanView 打开 DLL 并将结果保存为 .gif 或 .jpg。

我知道这个问题很旧,但这是“从 dll 中提取图标”的第二次谷歌点击,我想避免在我的工作站上安装任何东西,我记得我使用 IrfanView。

您可以下载免费软件 资源黑客 然后按照以下说明操作:

  1. 打开您想要从中查找图标的任何 dll 文件。
  2. 浏览文件夹以查找特定图标。
  3. 从菜单栏中选择“操作”,然后选择“保存”。
  4. 选择 .ico 文件的目标位置。

参考 : http://techsultan.com/how-to-extract-icons-from-windows-7/

如果您使用的是 Linux,则可以使用以下命令从 Windows DLL 中提取图标 gExtractWinIcons。它可以在 Ubuntu 和 Debian 中使用 gextractwinicons 包裹。

这篇博客文章有一个 屏幕截图和简要说明.

还有一个可用的资源,即 Visual Studio 图像库,它“可用于创建在视觉上与 Microsoft 软件一致的应用程序”,大概需要获得底部给出的许可。https://www.microsoft.com/en-ca/download/details.aspx?id=35825

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top