gpt4 book ai didi

c# - System.Drawing.Bitmap GetBounds GraphicsUnit.Inch

转载 作者:太空狗 更新时间:2023-10-30 01:07:40 26 4
gpt4 key购买 nike

谁能告诉我如何从 GetBounds 获取除像素以外的任何单位的矩形?以下代码 - 直接从该函数的 MSDN 文档中提取 - 返回一个矩形,该矩形显然以像素而不是点(1/72 英寸)为单位。 (除非图标的大小为 32/72"x32/72"而不是我认为的 32x32 像素)。我最感兴趣的是使用以英寸为单位的矩形,但我只想看到 GetBounds pageUnit 参数导致返回的矩形发生变化。

Bitmap bitmap1 = Bitmap.FromHicon(SystemIcons.Hand.Handle);
Graphics formGraphics = this.CreateGraphics();
GraphicsUnit units = GraphicsUnit.Point;

RectangleF bmpRectangleF = bitmap1.GetBounds(ref units);
Rectangle bmpRectangle = Rectangle.Round(bmpRectangleF);
formGraphics.DrawRectangle(Pens.Blue, bmpRectangle);
formGraphics.Dispose();

最佳答案

这方面的信息有点稀疏,我能找到这个MSDN Forum posting这表明由于位图已经创建,单位已经设置并且不可更改。由于 GraphicsUnit 是通过引用传递的,如果您在调用后查看它,您会发现它从 Inch 设置回 Pixel。如果您真的想更改绘制矩形的大小,请设置 Graphics.PageUnit PropertyformGraphics 上到 GraphicsUnit 你想绘制矩形。

来自上面的链接:

In this sample, the parameters of Image.GetBounds method don’t change the result, because the bound of Bitmap has been decided. The parameters only determine the unit length to deal with the range, inch by inch or point by point. But the parameters will not influence the result.

强调我的

关于c# - System.Drawing.Bitmap GetBounds GraphicsUnit.Inch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11586362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com