'.NET: What does Graphics.DrawImageUnscaled do?

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

See also



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source