I've take some code and reduced it down to a few lines which still reproduce the error i am having. In this case, I am taking an image that is 448x298 in size and trying to overlay it on top of a white background that's 600x450.

So I'm expecting to get an image that's 600x450 with a white background and my original image laid on top of it starting in the upper right corner. And i expect my original image to remain it's original size. Instead the original image is going from 448x298 to approximately (give or take a pixel or two) 143x95

Here is the reduced code that's doing this:

                System.Drawing.Image oImage = new Bitmap(600, 450);
                Graphics oGraphic = Graphics.FromImage(oImage);
                oGraphic.FillRectangle(Brushes.White, 0, 0, 600, 450);
                oGraphic.DrawImage(image, new Point(0,0));
                return (Bitmap)oImage;
有帮助吗?

解决方案

You have to specify the target size. The overload you chose scales the image from the source dpi to the target dpi. As explained in another question, you should do this:

System.Drawing.Image oImage = new Bitmap(600, 450);
Graphics oGraphic = Graphics.FromImage(oImage);
oGraphic.FillRectangle(Brushes.White, 0, 0, 600, 450);
oGraphic.DrawImage(image, 0,0, image.Width, image.Height);
return (Bitmap)oImage;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top