Add Text Watermark to PNG using C#

Adding a text watermark to PNG images can enhance their visual appeal and provide additional information or branding elements. In this guide, we’ll explore the process of how to add text watermark to PNG using C# programming language. Before diving into the technical details, let’s first understand what a text watermark is in the context of PNG images. A text watermark is a visible overlay of text added to an image to convey supplementary information, such as copyright notices, branding, or ownership details. It acts as a form of visual identification and protection for the image. Below steps show how to insert text watermark to PNG in C#.

Steps to Add Text Watermark to PNG using C#

  1. Set up your development environment to utilize GroupDocs.Watermark for .NET library for adding a watermark to a PNG file
  2. Instantiate the Watermarker class, providing the PNG file path as an argument to its constructor
  3. Customize the TextWatermark class instance to align with your preferred watermark properties
  4. Incorporate the watermark into the PNG file using the Watermarker.Add method
  5. Store the updated PNG image on your disk using the Watermarker.Save method

By following these steps and leveraging the capabilities of C# and the Watermark library, you can effectively add text watermark in PNG using C#, enhancing their visual appeal and providing additional information or branding elements as needed. Having .NET installed on your device simplifies the execution of this process on various operating systems like Windows, macOS, or Linux, eliminating the necessity for extra software installations. Once you’ve configured the recommended library and adjusted file paths as needed, integrating the provided code into your projects should progress seamlessly. Following code example shows how to insert watermark on PNG image.

Code to Add Text Watermark to PNG using C#

using GroupDocs.Watermark.Common;
using GroupDocs.Watermark.Watermarks;
using GroupDocs.Watermark;
namespace AddTextWatermarktoPNGUsingCSharp
{
internal class Program
{
static void Main(string[] args)
{
// Set License to avoid the limitations of Watermark library
License lic = new License();
lic.SetLicense(@"GroupDocs.Watermark.lic");
// Specify an absolute or relative path to your PNG
using (Watermarker watermarker = new Watermarker("input.png"))
{
// Specify the desired text and font for the watermark
TextWatermark watermark = new TextWatermark("Watermark Text",
new Font("Arial", 60, FontStyle.Bold));
// Specify font color and text opacity, rotation and alignments
watermark.ForegroundColor = Color.DarkGreen;
watermark.Opacity = 0.5;
watermark.HorizontalAlignment = HorizontalAlignment.Center;
watermark.VerticalAlignment = VerticalAlignment.Center;
watermark.RotateAngle = -45;
// Apply the watermark
watermarker.Add(watermark);
// Save the resulting PNG
watermarker.Save("output.png");
}
}
}
}

In conclusion, the process of how to add text watermark to PNG in C# is straightforward and effective, especially with the versatility of the .NET framework. By following the steps outlined in this guide and utilizing the suggested library, you can enhance the visual appeal of your PNG files and convey additional information or branding elements. This technique provides a valuable tool for protecting your images and adding a professional touch to your projects. Experimenting with different watermark properties and customizations can further personalize your PNG images and make them stand out.

In a previous tutorial, we offered a comprehensive guide on adding text watermarks to JPG files using C#. If further guidance is needed, we recommend consulting our detailed tutorial on how to add text watermark to JPG using C#.

 English