In this how-to example, we’ll walk you through steps for how to add watermark in TIFF using C#. It is very simple to insert watermark in TIFF using C# by performing few API calls.
Steps to Insert Tiff Watermark using C#
- Install Aspose.Imaging for .NET NuGet package
- Include Aspose.Imaging, Aspose.Imaging.ImageOptions and Aspose.Imaging.Brushes namespaces
- Use Image.Load method to load the Tiff and add Tiff watermark
- Instantiate Graphics, Font, SolidBrush and StringFormat classes objects to set the font, color and textual properties of watermark
- Using Graphics class object protect Tiff with watermark in C#
- Save output image with Tiff watermark
In the afore mentioned steps, we have loaded the Tiff image first in memory using Load method of Image class. Then we have specified attributes for Font, Brush and Text formatting to protect Tiff with watermark in C#. Lastly, we are saving Tiff watermark using C#.
Code to Insert Tiff Watermark using C#
using System; | |
using Aspose.Imaging; | |
using Aspose.Imaging.Brushes; | |
using Aspose.Imaging.ImageOptions; | |
namespace AddingTiffWatermark | |
{ | |
class TiffWatermark | |
{ | |
static void Main(string[] args) | |
{ | |
string PathForTiffFile = @"Y:\Downloads\"; | |
//Load the License file | |
License license = new License(); | |
license.SetLicense(PathForTiffFile + "Conholdate.Total.Product.Family.lic"); | |
// Use Image.Load to add tiff watermark using c# in Tiff file | |
using (var image = Aspose.Imaging.Image.Load(PathForTiffFile + "TiffToWatermark.tiff")) | |
{ | |
// Initialize Graphics class instance for loaded Tiff Image | |
Graphics graphics = new Aspose.Imaging.Graphics(image); | |
// Initialize SizeF to store image Size | |
Size size = graphics.Image.Size; | |
// Create an instance of Font to set the font Name, Size and Style | |
Font font = new Aspose.Imaging.Font("Arial", 24, | |
Aspose.Imaging.FontStyle.Bold); | |
// Instantiate SolidBrush and set Color and Opacity | |
SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(); | |
brush.Color = Aspose.Imaging.Color.Red; | |
brush.Opacity = 0; | |
// initialize an object of StringFormat class and | |
// set its various textual properties | |
StringFormat format = new Aspose.Imaging.StringFormat(); | |
format.Alignment = Aspose.Imaging.StringAlignment.Near; | |
format.FormatFlags = Aspose.Imaging.StringFormatFlags.FitBlackBox; | |
// Render the string on image with set font and brush | |
graphics.DrawString("PROTECTED", font, | |
brush, 0, 0, format); | |
// Save protected tiff with watermark in c# | |
image.Save(PathForTiffFile+"WatermarkedTiff.tiff"); | |
} | |
} | |
} | |
} |
Using the above example, you can easily protect Tiff with watermark in C# in your .NET projects including Windows desktop, ASP.NET web, or console applications.