How to watermark emf/wmf image

How to watermark emf/wmf image

Issue : How to watermark emf/wmf image.

Tips : To properly watermark emf/wmf image, it is needed to use WmfRecorderGraphics2D and EmfRecorderGraphics2D classes to work with graphics in those formats.

Example :

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
// load an existing EMF with Image.Load
using (var image = Aspose.Imaging.Image.Load(@"template.emf"))
{
// create and initialize an instance of Graphics class and Initialize an object of SizeF to store image Size
Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D graphics =
Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D.FromEmfImage(
(Aspose.Imaging.FileFormats.Emf.EmfImage)image);
var size = image.Size;
// create an instance of Font. Initialize it with Font Face, Size and Style
var font = new Aspose.Imaging.Font("Times New Roman", 20, Aspose.Imaging.FontStyle.Bold);
// draw the string on image
graphics.DrawString("CONFIDENTIAL", font, Aspose.Imaging.Color.Red, 0, 30);
Aspose.Imaging.FileFormats.Emf.EmfImage image2 = graphics.EndRecording();
// save output to disc
image2.Save(@"output.emf");
}
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
// load an existing WMF with Image.Load
using (var image = Aspose.Imaging.Image.Load(@"template.wmf"))
{
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D wmfGraphics = Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D.FromWmfImage((Aspose.Imaging.FileFormats.Wmf.WmfImage)image);
var size = image.Size;
// create an instance of Font. Initialize it with Font Face, Size and Style
var font = new Aspose.Imaging.Font("Times New Roman", 20, Aspose.Imaging.FontStyle.Bold);
// draw the string on image
wmfGraphics.DrawString("CONFIDENTIAL", font, Aspose.Imaging.Color.Red, 50, 50);
Aspose.Imaging.FileFormats.Wmf.WmfImage im2 = wmfGraphics.EndRecording();
im2.Save(@"output.wmf");
}