C# 如何使用C从图标文件中检索最大的可用图像#

C# 如何使用C从图标文件中检索最大的可用图像#,c#,.net,system.drawing,C#,.net,System.drawing,我需要从包含多个图像大小的图标文件(.ico)中检索最大的位图图像 在我的图标编辑器中,我可以看到图标文件中有几个图像,即16x16px、24x24、32x32、48x48和256x256 但是,以下代码行丢失了我想要的256x256图像: var iconObj = new System.Drawing.Icon(TempFilename); //iconObj is 32x32 //get the 'default' size image: var image1 = iconObj.ToBi

我需要从包含多个图像大小的图标文件(.ico)中检索最大的位图图像

在我的图标编辑器中,我可以看到图标文件中有几个图像,即16x16px、24x24、32x32、48x48和256x256

但是,以下代码行丢失了我想要的256x256图像:

var iconObj = new System.Drawing.Icon(TempFilename); //iconObj is 32x32
//get the 'default' size image:
var image1 = iconObj.ToBitmap(); //retrieved image is 32x32
//get the largest image up to 1024x1024:
var image2 = new System.Drawing.Icon(iconObj, new System.Drawing.Size(1024, 1024)).ToBitmap(); //retrieved image is 48x48

如何从图标文件中获取可用的最大图像(或特定大小的图像)?

看起来,Microsoft在其实现中存在缺陷,而不是接受 “图标格式”指定以像素为单位的图像宽度。可以 0到255之间的任意数字。值0表示图像宽度为256 像素”。因此,从图标返回的图标的最大大小(字符串,大小) 可以是128x128。 我发现了这个解决方法:当我指定-1,-1作为高度和宽度时,结果将是256x256图标(我不确定ico文件中图像的任何顺序,不提供按规格按大小排序,我只是在我的项目中使用它)


可能会有帮助OYes,似乎是这样的。如果我将目标高度和宽度减少到128或更少,它将按预期工作。
using System;
using System.Drawing;

static class Program
{

    static void Main()
    {
        Icon image2 = new System.Drawing.Icon("Softskin-Series-Folder-Folder-BD-Files.ico",-1,-1);
        Console.WriteLine( "height={0} width={1}",image2.Height,image2.Width    ); 

    }
}