Use the .NET image processing API to add a watermark to images using C#. Add a watermark to PNG, JPEG, BMP, and other popular image formats in C#. Get started with the Aspose Plugin for just $99.
March 8, 2021 · 3 min · Usman Aziz
Watermarks are essential for asserting ownership of images and preventing unauthorized usage or counterfeiting. In many scenarios, implementing an automated watermarking feature in your web or desktop applications is necessary. This article will guide you through the process of adding watermarks to images programmatically using C#. You’ll also learn how to efficiently watermark a batch of images. Let’s dive in!
To add watermarks to images, we will utilize the Aspose.Imaging for .NET. This powerful image processing API supports a variety of image formats, including PNG, JPEG, and BMP, and simplifies image manipulation. You can either download the API binaries or install it via NuGet using the following command:
PM> Install-Package Aspose.Imaging
## Add Watermark to an Image in C# {#Add-Watermark-to-an-Image-in-csharp}Here’s a step-by-step guide on how to add a watermark to an image using C#:
1. Load the image using the [Image](https://reference.aspose.com/imaging/net/aspose.imaging/image) class.
2. Create an instance of the [Graphics](https://reference.aspose.com/imaging/net/aspose.imaging/graphics) class, initializing it with the [Image](https://reference.aspose.com/imaging/net/aspose.imaging/image) object.
3. Define the font family, size, and style using the [Font](https://reference.aspose.com/imaging/net/aspose.imaging/font) class.
4. Create a [SolidBrush](https://reference.aspose.com/imaging/net/aspose.imaging.brushes/solidbrush) instance to set properties like color.
5. Instantiate the [StringFormat](https://reference.aspose.com/imaging/net/aspose.imaging/stringformat) class to manage text alignment.
6. Add the watermark to the image using the [Graphics.DrawString(String, Font, SolidBrush, 0, 0, StringFormat)](https://reference.aspose.com/imaging/net/aspose.imaging.graphics/drawstring/methods/5) method.
7. Save the image using the [Image.Save(String)](https://reference.aspose.com/imaging/net/aspose.imaging.datastreamsupporter/save/methods/2) method.
Here’s a code sample demonstrating how to add a watermark to an image in C#:
## C# Add Diagonal Watermark to Images {#Add-Diagonal-Watermark-to-images-in-csharp}In some cases, watermarks are applied diagonally across images. The Aspose.Imaging for .NET API allows you to rotate the watermark text to achieve this effect. Follow these steps to add a diagonal watermark:
1. Load the image using the [Image](https://reference.aspose.com/imaging/net/aspose.imaging/image) class.
2. Create a [Graphics](https://reference.aspose.com/imaging/net/aspose.imaging/graphics) instance initialized with the [Image](https://reference.aspose.com/imaging/net/aspose.imaging/image) object.
3. Define the font family, size, and style with the [Font](https://reference.aspose.com/imaging/net/aspose.imaging/font) class.
4. Create a [SolidBrush](https://reference.aspose.com/imaging/net/aspose.imaging.brushes/solidbrush) instance to set properties like color.
5. Instantiate a [StringFormat](https://reference.aspose.com/imaging/net/aspose.imaging/stringformat) object for text alignment.
6. Create a [Matrix](https://reference.aspose.com/imaging/net/aspose.imaging/matrix) instance to set the transformation angle.
7. Assign the Matrix object to the [Graphics.Transform](https://reference.aspose.com/imaging/net/aspose.imaging/graphics/properties/transform) property.
8. Add the watermark using the [Graphics.DrawString(String, Font, SolidBrush, 0, 0, StringFormat)](https://reference.aspose.com/imaging/net/aspose.imaging.graphics/drawstring/methods/5) method.
9. Save the image using the [Image.Save(String)](https://reference.aspose.com/imaging/net/aspose.imaging.datastreamsupporter/save/methods/2) method.
Here’s a code sample that illustrates how to add a diagonal watermark to images using C#:
## Insert Watermark on Images with a Free License {#Get-a-Free-API-License}You can [get a free temporary license](https://purchase.aspose.com/temporary-license) to insert watermarks on images without any evaluation limitations.
## ConclusionIn this article, you learned how to add a watermark to images in C#. You also discovered how to rotate watermark text to a specific angle. For further information about the C# image processing API, please refer to the [documentation](https://docs.aspose.com/imaging/net/getting-started/). If you have any questions or need assistance, feel free to reach out via our [forum](https://forum.aspose.net/).
## See Also* [Compress PNG, JPEG, and TIFF Images using C#](https://blog.aspose.com/imaging/compress-png-jpeg-and-tiff-images-using-csharp/)