.NET:是什么Graphics.DrawImageUnscaled办?NET、Graphics、DrawImageUnscaled

由网友(濄期的埘堠ン)分享简介:有不为人熟知的,如果你绘制图像,例如:graphics.DrawImage(图像,顶部,左侧);的图像将被缩小。这是因为 的DrawImage 着眼于图像的DPI设置(如为72dpi从Photoshop),和缩放图像以匹配目标显示(通常为96DPI)。 如果你想绘制的图像而没有任何缩放,你必须明确地给的DrawIma...

有不为人熟知的,如果你绘制图像,例如:

  graphics.DrawImage(图像,顶部,左侧);
 

的图像将被缩小。这是因为 的DrawImage 着眼于图像的DPI设置(如为72dpi从Photoshop),和缩放图像以匹配目标显示(通常为96DPI)。

graphicspace.net.jpg网站截图33

如果你想绘制的图像而没有任何缩放,你必须明确地给的DrawImage 图像的尺寸:

  graphics.DrawImage(IMG,上,左,img.Width,img.Height);
 

我知道这从多年的GDI +编程。同样的事实存在于.NET System.Drawing中各地GDI +包装 - 如果你想绘制图像缩放的,你必须强迫它扩展到原来的大小。

这就是为什么我是pssed找到在.NET中的 DrawImageUnscaled 方法IM $ P $:

  graphics.DrawImageUnscaled(IMG,顶部,左侧);
 

除了将图像仍然缩放;使得它等同于:

  graphics.DrawImage(IMG,顶部,左侧);
 

如果你想绘制图像缩放的,你必须不断地打电话:

  graphics.DrawImage(IMG,上,左,img.Width,img.Height);
 

这让我想起我的问题:什么呢 DrawImageUnscaled 如果没有绘制图像缩放的

从MSDN

Graphics.DrawImageUnscaled方法(图像的Int32,Int32)在

  

使用绘制的原始物理大小在由坐标对指定的位置指定的图像。

Graphics.DrawImage方法(图像的Int32,Int32)在

  

绘制指定的图像,利用其原有的物理尺寸,在由坐标对指定的位置。

Graphics.DrawImage方法(图像的Int32,的Int32,的Int32,Int32)在

  

绘制指定的Image的指定位置,并使用指定的尺寸。

另请参见

MSDN:如何:避免自动缩放提高性能 解决方案

Graphics.DrawImageUnscaled方法(图像的Int32,Int32)在没有做任何事情不同于的DrawImage(图像,的Int32,Int32)在

例如。

 公共无效DrawImageUnscaled(图片形象,诠释的x,int y)对
{
    this.DrawImage(图像中,x,y)基
}
 

不过了发生在一个高度的方法,宽度或矩形不同。这些方法要么忽略的高度和宽度或与矩形仅使用顶部和左

我的猜测是, DrawImageUnscaled方法(图像的Int32,Int32)在存在奇偶原因,并没有做缩放,由于新闻部差异的来源和目标设备。

It is not well known, that if you draw an image, e.g.:

graphics.DrawImage(image, top, left);

the image will be scaled. This is because DrawImage looks at the dpi setting of the image (e.g. 72dpi from photoshop), and scales the image to match the destination display (typically 96dpi).

If you want to draw an image without any scaling, you must explicitly give DrawImage the size of the image:

graphics.DrawImage(img, top, left, img.Width, img.Height);

i knew this from years of programming in GDI+. The same fact exists in the .NET System.Drawing wrappers around GDI+ - if you want to draw an image unscaled you must force it to scale to the original size.

Which is why i was impressed to find a DrawImageUnscaled method in .NET:

graphics.DrawImageUnscaled(img, top, left);

Except that the image is still scaled; making it identical to:

graphics.DrawImage(img, top, left);

and if you want to draw an image unscaled you must continue to call:

graphics.DrawImage(img, top, left, img.Width, img.Height);

Which brings me to my question: what does DrawImageUnscaled if not to draw an image unscaled?

From MSDN

Graphics.DrawImageUnscaled Method (Image, Int32, Int32)

Draws the specified image using its original physical size at the location specified by a coordinate pair.

Graphics.DrawImage Method (Image, Int32, Int32)

Draws the specified image, using its original physical size, at the location specified by a coordinate pair.

Graphics.DrawImage Method (Image, Int32, Int32, Int32, Int32)

Draws the specified Image at the specified location and with the specified size.

See also

MSDN: How to: Improve Performance by Avoiding Automatic Scaling

解决方案

Well Graphics.DrawImageUnscaled Method (Image, Int32, Int32) doesn't do anything different than DrawImage (Image, Int32, Int32)

e.g.

public void DrawImageUnscaled(Image image, int x, int y)
{
    this.DrawImage(image, x, y);
}

However the methods that take in a Height, Width or a rectangle are different. Those methods either ignore the height and width or with the rectangle only use the top and left.

My guess is that DrawImageUnscaled Method (Image, Int32, Int32) exists for parity reasons and doesn't have to do with scaling due to dpi difference in the source and target device.

阅读全文

相关推荐

最新文章