I'm drawing an image of 100 x 100 pixels in a PDFSharp document.
The image is drawn using:
g.DrawImage(image, new Point(x, y));
The issue here is that if I draw a rectangle starting in the same coordinates x,y and using 100x100 as dimensiones... the rectangle is larger than the image.
If I use the other overloads in DrawImage, setting the container rectangle, the image fits the rectangle but it loses quality (it is enlarged).
I think it is a problem of different resolutions or something like that.
Any ideas?
UPDATE: I resized the image to 133x133 to fit the 100x100 rectangle. What is the reason of this difference? A 33% difference.
MY SOLUTION: When retrieving the image and scaling it to fit the rectangle, you need to take into account that the size of your image is in PIXELS and when you draw in the PDF it is in points. If your image is in 96 DPI, you need to increase its dimension multiplying by "96/72" (that is the 33% I got), and that way you will see what you expect (even if you draw it using a container rectangle or just the starting coordinates).
Set image.Interpolate = false;
to disable anti-aliasing and increase the sharpness of the small image.
DrawImage
without specifying a size. – I liked the old Stack Overflow