Adding a Watermark to an Image
Adding a Watermark to an Image
This document explains how to add a watermark to an image using Aspose.Imaging. Adding a watermark to an image is a common requirement for image processing applications. This example uses the Graphics class to draw a string on the image surface.
Adding a Watermark
To demonstrate the operation, we will load a BMP image from disk and draw a string as the watermark on the image surface using the Graphics class' DrawString method. We’ll save the image to PNG format using the PngOptions class. Below is a code example that demonstrates how to add a watermark to an image. The example source code has been split into parts to make it easy to follow. Step by step, the examples show how to:
- Load an image.
- Create and initialize a Graphics object.
- Create and initialize Font and SolidBrush objects.
- Draw a string as watermark using the Graphics class' DrawString method.
- Save image to PNG.
The following code snippet shows you how to add watermark on the image.
Adding a Diagonal Watermark
Adding a diagonal watermark to an image is similar to adding a horizontal watermark as discussed above, with a few differences. To demonstrate the operation, we will load a JPG image from disk, add transformations using an object of Matrix class and draw a string as the watermark on the image surface using the Graphics class' DrawString method. Below is a code example that demonstrates how to add a diagonal watermark to an image. The example source code has been split into parts to make it easy to follow. Step by step, the examples show how to:
- Load an image.
- Create and initialize a Graphics object.
- Create and initialize Font and SolidBrush objects.
- Get size of image in SizeF object.
- Create an instance of Matrix class and perform composite transformation.
- Assign transformation to Graphics object.
- Create and initialize a StringFormat object.
- Draw a string as watermark using the Graphics class' DrawString method.
- Save resultant image.
The following code snippet shows you how to add a diagonal watermark.