From: Mihajlo Cvetanović on
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?
From: Jackie on
Mihajlo Cvetanović wrote:
> 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."

--
Regards,
Jackie
From: Peter Duniho on
Mihajlo Cvetanović wrote:
> 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?

Jackie's reply shows the documentation for the relevant types and
methods. Hopefully that provides some insight.

In some cases, the two lines will in fact produce identical results. In
other cases, they won't (depending on the resolution of the Graphics and
the Image being drawn). So without a concise-but-complete code example
from you that reliably demonstrates the problem, it's not really
possible to say specifically why in your case there's a problem.

Pete
 | 
Pages: 1
Prev: Socket Timeout at 2min
Next: force kill thread