Q: C# Application changes picture size on me I'm working on a program where I need to place an image on top of another image. What happening though is when I place the picture on top of the background it gets changed to a different resolution and I'm not sure why. I've tried messing around with the bit depth and DPI, but neither of them made any difference. My original image is 574x574, but when it places it on the picture, it becomes 768x768. Here is the code I'm 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);


A: When you call Graphics.DrawImage without specifying the destination rectangle, it assumes that you want to preserve the original physical size of the image (i.e. inches rather than pixels), so the image is resized based upon the DPI of the source image and the destination image.
If you want to ensure that the image gets drawn at the original pixel size without adjusting the DPIs then you just need to provide the entire destination rectangle.
grfx.DrawImage(imgPicture1, dstRect, srcRect, GraphicsUnit.Pixel);

