UWP: Place a small image on another larger image

catalina beaver 41 Reputation points
2022-04-14T11:42:28.383+00:00

Hi,

I'm trying to place a small QR code on a larger template image. It seems this is easy doing in Forms. However, it seems difficult for me doing in UWP.
I'm doing in UWP with the help of canvas. I place the larger image in canvas and placing the QR code over it and making the whole canvas as image.
The issue with above canvas approach is, I need to make the 1920*1080 image from the canvas. I can not keep such large image in the canvas as the page has other buttons/textboxes. Hence I'm keeping the QR code above the canvas which has size Width="1070" and Height="580". I'm attaching the code I used in the windows forms. I have to use UWP only.
using (System.Drawing.Image image = System.Drawing.Image.FromFile(@"template image location"))
using (System.Drawing.Image watermarkImage = System.Drawing.Image.FromFile(@"qr code location"))
using (Graphics imageGraphics = Graphics.FromImage(image))
using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage))
{
int x = (image.Width / 2 - watermarkImage.Width / 2);
int y = (image.Height / 2 - watermarkImage.Height / 2);
watermarkBrush.TranslateTransform(x, y);
imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new System.Drawing.Point(x, y), new System.Drawing.Size(watermarkImage.Width + 1, watermarkImage.Height)));
image.Save(@"output image location");
}

Universal Windows Platform (UWP)
{count} votes