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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With