Improved Handling of Text Watermark
This release of the API has fixed the issue where font style underline was not previously working in watermarks.
Steps to programmatically apply underline to watermark using C#
1. Load the image.
Use the Watermark
class constructor to load the image you want to add the watermark to.
string imagePath = @"C:\Docs\UnderlineFontStyle.png";
Watermarker watermarker = new Watermark(imagePath);
2. Create a font.
Create a new Font
object with the desired font name, size, and style. In this example, we are using a 19-point Arial font with bold, italic, and underline styles.
Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
3. Create a text watermark.
Create a new TextWatermark
object with the desired text and font. In this example, we are creating a text watermark with the text “Test watermark” and the font we created in the previous step.
TextWatermark watermark = new TextWatermark("Test watermark", font);
4. Set the watermark properties.
Set the foreground color, background color, text alignment, and opacity of the watermark. In this example, we are setting the foreground color to blue, the background color to yellow, the text alignment to center, and the opacity to 1.0 (fully opaque).
watermark.ForegroundColor = Color.Blue;
watermark.BackgroundColor = Color.Yellow;
watermark.TextAlignment = TextAlignment.Center;
watermark.Opacity = 1.0;
5. Add the watermark to the image.
Add the watermark to the image using the Add()
method of the Watermarker
class.
watermarker.Add(watermark);
6. Save the watermarked image.
Save the watermarked image to disk using the Save()
method of the Watermarker
class.
string outputPath = @"C:\Docs\OutputImage.png";
watermarker.Save(outputPath);
Complete Code for Applying Underlined Text Watermark on PNG
string imagePath = @"C:\Docs\UnderlineFontStyle.png";
string outputPath = @"C:\Docs\OutputImage.png";
using (Watermarker watermarker = new Watermarker(imagePath))
{
Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
TextWatermark watermark = new TextWatermark("Test watermark", font);
watermark.ForegroundColor = Color.Blue;
watermark.BackgroundColor = Color.Yellow;
watermark.TextAlignment = TextAlignment.Center;
watermark.Opacity = 1.0;
watermarker.Add(watermark);
watermarker.Save(outputPath);
}
For a complete list of features, enhancements, and bug fixes in this release please visit, GroupDocs.Watermark for .NET 23.4.