How to Add Image Watermark to PSD in C#

In this step by step tutorial, you’ll learn how to add image watermark to PSD in C#. When you watermark PSD file, you make it harder for the counterfeiters to create an illegal copy of the document.

Steps to Add Image Watermark to PSD in C#

  1. Install Aspose.PSD for .NET package from NuGet.org
  2. Use the required namespaces to make the code work
  3. Set license of Aspose.PSD for .NET API using SetLicense method
  4. Load input PSD file into PsdImage object object using Image class
  5. Create a base Layer object using an image from FileStream
  6. Add base layer object to the PSD image object created above
  7. Load watermark image into a Layer object
  8. Draw watermark image on the base layer
  9. Save the final watermarked PSD file as an output

As you can see, it’s quick and easy to watermark PSD file using Aspose.PSD for .NET. It does not require you to have Photoshop installed on your system. And the code given below, can be used to add watermark feature in your applications.

Code to Add Image Watermark to PSD in C#

using System;
using System.IO;
//Add reference to Aspose.PSD for .NET API
//Use following namespaces to add image watermark to PSD file
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers;
using Aspose.PSD.Brushes;
using Aspose.PSD.ImageOptions;
namespace AddImageWatermarkToPSD
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before adding image watermark to PSD
//using Aspose.PSD for .NET
Aspose.PSD.License AsposePSDLicense = new Aspose.PSD.License();
AsposePSDLicense.SetLicense(@"c:\asposelicense\license.lic");
//Load a PSD file into PsdImage object
PsdImage PSDFileToAddImageWatermark = (PsdImage)Image.Load("PSDFileToAddImageWatermark.psd");
//load a watermark image as into a layer
FileStream BaseLayerFile = new FileStream("BaseLayer.png", FileMode.Open);
Layer BaseLayer = new Layer(BaseLayerFile);
//add layer to PSD file
PSDFileToAddImageWatermark.AddLayer(BaseLayer);
//load a watermark image into a layer
FileStream ImageWatermarkFile = new FileStream("ImageWatermark.bmp", FileMode.Open);
Layer ImageWatermarkLayer = new Layer(ImageWatermarkFile);
//add image watermark to base layer
BaseLayer.DrawImage(new Point(0, 0), ImageWatermarkLayer);
//save final watermarked PSD file
PSDFileToAddImageWatermark.Save("ImageWatermarkedPSD.psd", new PsdOptions());
}
}
}

In this sample, you learned the steps to add image watermark to PSD in C#. However, in the similar way, you can also add text watermark to PSD in C# code. We’ll add those steps in a separate how to topic. This C# code can be used with any kind of .NET applications be it ASP.NET web applications, Windows applications, or Services etc.

 English