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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…