C # app resize image on me

I am working on a program where I need to place an image on top of another image. What happens when I put a picture on top of the background is changed to a different resolution and I'm not sure why. I've tried communicating with bit depth and DPI, but none of them made any difference. My original image is 574x574, but when it puts it on the image it becomes 768x768. Here is the code I am using. Any help is appreciated.

Image imgBackground = Image.FromFile(r_strApplicationStartupPath + "\\images\\Backing.png");
Image imgPicture1 = Image.FromFile(r_strApplicationStartupPath + "\\images\\Picure1.png");
Image TempImg = Image.FromFile(r_strApplicationStartupPath + "\\images\\Backing.png");
Graphics grfx = Graphics.FromImage(TempImg);
Bitmap bmpFinal = new Bitmap(1296, 1944, PixelFormat.Format32bppArgb);
grfx = Graphics.FromImage(bmpFinal);
grfx.DrawImage(imgBackground, 0, 0);
grfx.DrawImage(imgPicture1, 659, 1282);
bmpFinal.Save(r_strApplicationStartupPath + "\\images\\" + r_strName + " Composite " + r_intCounter.ToString() + ".png", ImageFormat.Png);

      

+3


source to share


1 answer


When you call Graphics.DrawImage without specifying a target rectangle, it is assumed that you want to maintain the original physical size of the image (i.e. inches, not pixels), so the image is resized based on the DPI of the source image and the target image.

If you want the image to be drawn at its original pixel size without DPI adjustment, you just need to provide the entire destination rectangle.



grfx.DrawImage(imgPicture1, dstRect, srcRect, GraphicsUnit.Pixel);

      

+5


source







All Articles