Image size mystery

  • Thread starter Mihajlo Cvetanović
  • Start date
M

Mihajlo Cvetanović

Let's say I have an Image and Graphics g. I would expect the following
two lines to produce same result, but they don't. Does anyone know why?

g.DrawImage(image, new Rectangle(position, image.Size));
g.DrawImage(image, position);

What is the true image's size in given graphics context? I.e, what
should stand instead of image.Size so that two lines produce the same
result?
 
J

Jackie

Mihajlo said:
Let's say I have an Image and Graphics g. I would expect the following
two lines to produce same result, but they don't. Does anyone know why?

g.DrawImage(image, new Rectangle(position, image.Size));
g.DrawImage(image, position);

What is the true image's size in given graphics context? I.e, what
should stand instead of image.Size so that two lines produce the same
result?

I can't really give a good answer at the moment, but until someone else
gives a good, short answer to this, I hope any of this can make sense
because it sounds to me like it has something to do with it (scaling).

-----

Graphics.DrawImage Method (Image, Point)
http://msdn.microsoft.com/en-us/library/42807xh1.aspx
"Draws the specified Image, using its original physical size, at the
specified location."

Remarks:
"An Image stores a value for pixel width and a value for horizontal
resolution (dots per inch). The physical width, measured in inches, of
an image is the pixel width divided by the horizontal resolution. For
example, an image with a pixel width of 216 and a horizontal resolution
of 72 dots per inch has a physical width of 3 inches. Similar remarks
apply to pixel height and physical height.

This method draws an image using its physical size, so the image will
have its correct size in inches regardless of the resolution (dots per
inch) of the display device. For example, suppose an image has a pixel
width of 216 and a horizontal resolution of 72 dots per inch. If you
call this method to draw that image on a device that has a resolution of
96 dots per inch, the pixel width of the rendered image will be
(216/72)*96 = 288."

-----

Graphics.DrawImage Method (Image, Rectangle)
http://msdn.microsoft.com/en-us/library/yws82c40.aspx
"Draws the specified Image at the specified location and with the
specified size."

Remarks:
"The image represented by the image object is scaled to the dimensions
of the rect rectangle."

-----

Size Structure
http://msdn.microsoft.com/en-us/library/system.drawing.size.aspx
"The unit for the Height and Width of the Size structure depend on the
PageUnit and PageScale settings for the Graphics object that is used
to draw."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top