Put Signature on Photo using C#

This article guides on how to put signature on photo using C#. It has details to set the IDE, a list of steps, and a sample code showing how to put a signature on photos using C#. It will explain the process to make the PNG signature transparent and render it on the target image in PNG, JPG, or any other supported format as per the requirements.

Steps to Put Signature on Image using C#

  1. Set the environment to use Aspose.Imaging for .NET to put a signature on an image
  2. Load the target image and signature image in PNG format as a RasterImage object
  3. Cache the signature image in memory for accessing and editing each of the pixels in it
  4. Go through each pixel in the signature image and set each white pixel transparent by setting its Alpha value to 0
  5. Save the modified pixel to make the white background transparent in the signature image
  6. Create an instance of the Graphics class using the target image
  7. Render the signature image over the target image at the specified position using the DrawImage method
  8. Save the resultant image as a PNG image with a transparent signature on it

These steps summarize the process of how to put signature on a picture using C#. Load the main image in any format, signature image in PNG format, cache the signature image in memory, access each pixel and set all the white pixels transparent by setting the Alpha value to 0. Finally, save the signature image with updated pixels, link the main image with the Graphic object and use the DrawImage method to render the transparent signature on the main image.

Code to Insert Signature in JPG using C#

This code has demonstrated how to put signature in JPG using C#. We use the LoadArgb32Pixels() method to access the pixels in a byte array, get R, G, and B values, check their values if each is higher than 240 (whitish), then we set the Alpha value to 0. We can also set the size of the signature to a specified size by un-commenting the code in the beginning, as per the needs.

This article has taught us how to put signatures on images. To convert a DNG file to JPG, refer to the article on Convert DNG to JPG in C#.