Watermarks in images are usually used to claim ownership of the content. On the other hand, images are watermarked to avoid unauthorized usage or counterfeiting. In various cases, you may need to automate watermarking feature within your web or desktop applications. For such scenarios, this article covers how to add watermark to images programmatically in C#. This could also be useful when you need to watermark a batch of images in one go. So let’s begin.
- C# API to Add Watermark to Images
- Add Watermark to an Image in C#
- Add Diagonal Watermark to images in C#
- Get Free API License
Add Watermark to Images in C# - API Installation
To add watermarks to images, we’ll use Aspose.Imaging for .NET. It is a powerful image-processing API that supports a wide range of image formats. Furthermore, the API makes it easier for you to manipulate the images. You can either download binaries of the API or get it installed using NuGet.
PM> Install-Package Aspose.Imaging
Add Watermark to an Image in C#
The following are the steps to add a watermark to an image using C#.
- Load the image using Image class.
- Create an instance of Graphics class and initialize it with Image object.
- Set font family, size, and face using Font class.
- Create an instance of SolidBrush class and set its properties such as color etc.
- Instantiate StringFormat class to set text alignment.
- Add watermark to the image using Graphics.DrawString(String, Font, SolidBrush, 0, 0, StringFormat) method.
- Save the image using Image.Save(String) method.
The following code sample shows how to add a watermark to an image in C#.
C# Add Diagonal Watermark to Images
In various cases, watermarks are applied to the images diagonally. For this, Aspose.Imaging for .NET allows you to transform the watermark text on a certain angle. The following are the steps to add a diagonal watermark to an image.
- Load the image using Image class.
- Create an instance of Graphics class and initialize it with Image object.
- Set font family, size, and face using Font class.
- Create an instance of SolidBrush class and set its properties such as color etc.
- Instantiate StringFormat class to set text alignment.
- Create an instance of Matrix class and set transformation angle.
- Assign Matrix object to Graphics.Transform property.
- Add watermark using Graphics.DrawString(String, Font, SolidBrush, 0, 0, StringFormat) method.
- Save the image using Image.Save(String) method.
The following code sample shows how to add a diagonal watermark to images using C#.
Insert Watermark on Images with a Free License
You can get a free temporary license and insert a watermark on images without evaluation limitations.
Conclusion
In this article, you have learned how to add a watermark to images in C#. Furthermore, you have seen how to transform watermark text to a particular angle. You can explore more about C# image processing API using documentation. In case you would have any questions or queries, contact us via our forum.