This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/editor/manipulation/replace-colors-from-image.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. 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 key

Load the source image

Create a GdPictureImaging instance and load the image:

using GdPictureImaging imaging = new GdPictureImaging();
// Load the image that contains colors to be replaced
int imageId = imaging.CreateGdPictureImageFromFile(@"input.png");

Replace colors

Run the color swap operation:

// Execute the color replacement operation
imaging.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 colors
imaging.SaveAsPNG(imageId, @"output.png");

Conclusion

This workflow replaces selected colors in an image and saves a standardized output file.