【问题标题】:Icon Resize Constructor Returning Incorrect Size图标调整大小构造函数返回不正确的大小
【发布时间】:2015-05-02 00:56:45
【问题描述】:

我正在尝试使用 System.Drawing.Icon(System.Drawing.Icon, int, int) 调整嵌入在我的应用程序中的 ICO 文件的大小,但我总是得到一个大小为 32x32 像素的图标,与原始图标大小相同(由 Icon.ExtractAssociatedIcon(<main EXE file>) 返回。但是,有问题的 ICO 文件也包含 128x128 和 256x256 像素大小。为什么我无法从图标中获得更大的大小?

【问题讨论】:

    标签: winforms icons


    【解决方案1】:

    Icon.ExtractAssociatedIcon(...) 方法在内部使用 Shell32.dll 中的这个函数:

    IntPtr ExtractAssociatedIcon(IntPtr hInst, StringBuilder lpIconPath, out ushort lpiIcon)
    

    (http://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Icon.cs,8a5963a8e543d569),仅返回一种尺寸的图标(例如 32*32)。请参阅:http://www.pinvoke.net/default.aspx/shell32.extractassociatedicon

    所以,如果你调用这个构造函数重载:

    Icon iconOfAnotherSize = new Icon(original, newWidth, newHeight)
    

    那么您将获得与original 相同的图标,因为没有其他尺寸可用。

    要提取其他大小的图标,您可以尝试使用PrivateExtractIcons,这里是the example (Delphi)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 2022-01-21
      • 1970-01-01
      • 2019-05-06
      • 2020-08-21
      • 2020-06-15
      • 1970-01-01
      相关资源
      最近更新 更多