如何获得正确的图像高度和宽度

How to get the correct Image height and width

我正在尝试使用项目中图像的 HeightWidth 来计算 Rectangle 的大小。图像(图标)是 20px W 和 16px H。当我从 ImageList 加载它并查看图像尺寸时,它显示它是 16px X 16px。

我假设对图像应用了一些压缩,但我在这方面不是很有经验。我只需要获得正确的尺寸。 有什么办法吗?

注意:我不是从磁盘加载文件...它在我的项目中。

这就是我正在做的事情:

var tabPage = _tabControl.TabPages[e.Index];

var image = _tabControlImageList.Images[tabPage.ImageIndex];
var imageHW = Math.Max(image.Height, image.Width);

您可以而且必须在将 Images 加载到 ImageList 之前声明您想要的 ImageSize:

_tabControlImageList.ImageSize = new System.Drawing.Size(20, 16);

之后 ImageList 内的所有 Images 将具有以下尺寸:20x16px.