Replace colors in an image
Color replacement helps you standardize image appearance across document workflows.
Use this workflow when you need to:
- Enforce brand color consistency
- Correct scanned images with unwanted color casts
- Replace specific source colors in bulk processing pipelines
Prepare the project
Register the SDK license before running image-processing operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager licence = new LicenseManager();licence.RegisterKEY(""); // Set your license keyLoad the source image
Create a GdPictureImaging instance and load the image:
using GdPictureImaging imaging = new GdPictureImaging();
// Load the image that contains colors to be replacedint imageId = imaging.CreateGdPictureImageFromFile(@"input.png");Replace colors
Run the color swap operation:
// Execute the color replacement operationimaging.SwapColor(imageId, GdPicture14.Imaging.GdPictureColor.Black, GdPicture14.Imaging.GdPictureColor.Blue);SwapColor replaces every pixel matching the source color (black) with the target color (blue).
Save the modified image
Write the processed image to PNG:
// Save the modified image with replaced colorsimaging.SaveAsPNG(imageId, @"output.png");Conclusion
This workflow replaces selected colors in an image and saves a standardized output file.