Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#用户控件错误缩放图像_C#_Winforms_User Controls - Fatal编程技术网

C#用户控件错误缩放图像

C#用户控件错误缩放图像,c#,winforms,user-controls,C#,Winforms,User Controls,我有一个带有Image属性的usercontrol。该图像是resources.resx,大小为48x48 当我使用以下命令在控件上绘制图像时: e.Graphics.DrawImage(image, 0, 0); //or e.Graphics.DrawImageUnscaled(image, 0, 0); 图像始终缩放到其大小的1.5倍左右。保持图像大小的唯一方法是向方法传递一个矩形 为什么用户控件/图像的行为是这样的?当你说图像被缩放时,我想你指的是它的像素数 但DrawImage使用设

我有一个带有Image属性的usercontrol。该图像是resources.resx,大小为48x48

当我使用以下命令在控件上绘制图像时:

e.Graphics.DrawImage(image, 0, 0);
//or
e.Graphics.DrawImageUnscaled(image, 0, 0);
图像始终缩放到其大小的1.5倍左右。保持图像大小的唯一方法是向方法传递一个矩形


为什么用户控件/图像的行为是这样的?

当你说图像被缩放时,我想你指的是它的像素数

但DrawImage使用设备分辨率来保持其“物理尺寸”

请参见:

DrawImage方法使用图像的物理大小绘制图像,因此 图像将有其正确的大小,以英寸为单位 显示设备的分辨率(每英寸点数)。例如,假设 图像的像素宽度为216,水平分辨率为72 每英寸点数。如果调用DrawImage在设备上绘制该图像 分辨率为每英寸96点,即图像的像素宽度 渲染图像将为(216/72)*96=288

…这就是函数行为的原因


这个

图像的dpi为72,并且仍在缩放中。因此,您需要知道您的设备“dpi”。。。我不确定,但似乎你可以用