我正在尝试用另一个 jpg 图像为 jpg 图像加水印。如果我将生成的图像存储为新图像,它工作正常。是否可以仅使用水印图像更新原始图像文件?我不需要将其存储为不同的文件。
这是我的代码:
//watermark image
Bitmap sizedImg = (Bitmap)System.Drawing.Image.FromFile(@"C:\report branding.jpg");
//original file
System.Drawing.Bitmap template=(System.Drawing.Bitmap)System.Drawing.Image.FromFile(@"C:\CentralUtahCombined1.jpg");
Graphics g = Graphics.FromImage(template);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawImage(sizedImg, new Point(template.Width - sizedImg.Width,
template.Height - sizedImg.Height));
//watermarking the image but saving it as a different image file - here if I //provide the name as the original file name, it throws an error
string myFilename = @"C:\CentralUtah.jpg";
template.Save(myFilename);
template.Dispose();
sizedImg.Dispose();
g.Flush();