In professional document workflows, maintaining consistent visual branding and color schemes across diverse content presents ongoing challenges, particularly when dealing with scanned materials, legacy documents, or content sourced from multiple origins. Organizations frequently encounter situations where documents contain inconsistent colors, unwanted color casts from scanning processes, or branding elements that need standardization across document collections.

This sample demonstrates the technical implementation of intelligent color replacement, showcasing how businesses can automate visual standardization processes that would otherwise require manual image editing. The capability extends beyond simple color swapping to support sophisticated branding workflows, document standardization processes, and quality enhancement operations that ensure consistent visual presentation across entire document ecosystems.

Whether you’re standardizing corporate colors across archived materials, removing color inconsistencies introduced by various scanning devices, or adapting existing visual content to meet updated branding guidelines, the ability to programmatically replace specific colors enables automation strategies that maintain visual consistency while eliminating time-intensive manual editing processes.

Preparing the project

The first step is to initialize the SDK by registering the license. This needs to be done only once during the application’s lifetime and must occur before executing any further logic (see Getting Started with .NET SDK(opens in a new tab) for more details.)

using GdPicture14;
LicenseManager licence = new LicenseManager();
licence.RegisterKEY(""); // Set your license key

Loading the source image

The color replacement process begins by loading the target image into memory and preparing it for color analysis and modification operations.

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

The CreateGdPictureImageFromFile method loads the image into memory and returns an image identifier for subsequent operations. The SDK automatically detects the image format and applies appropriate loading parameters, supporting various formats including PNG, JPEG, TIFF, and other common image types used in business workflows.

Executing color replacement

The core replacement operation analyzes each pixel in the image, identifies matches based on the specified criteria, and replaces qualifying colors with the target color while preserving image structure and quality.

// Execute the color replacement operation
imaging.SwapColor(imageId, GdPicture14.Imaging.GdPictureColor.Black, GdPicture14.Imaging.GdPictureColor.Blue);

The SwapColor method performs intelligent color analysis and replacement throughout the entire image. This operation examines each pixel, calculates color distance from the source color using the specified tolerance, and replaces qualifying pixels with the target color while maintaining smooth transitions and preserving image quality.

Saving the modified image

The final step exports the color-corrected image to a file format suitable for distribution, archiving, or further processing within business workflows.

// Save the modified image with replaced colors
imaging.SaveAsPNG(imageId, @"output.png");

The SaveAsPNG method exports the modified image in PNG format, which provides lossless compression ideal for maintaining color accuracy after replacement operations. PNG format ensures that the precise color replacements are preserved without compression artifacts that might affect the visual consistency achieved through the color replacement process.