←Select platform

TranslateColor(RasterImage,RasterColor) Method

Summary
Translates the specified color in the image, and returns the nearest matching color in the destination image.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (LTRasterColor *)translateColor:(LTRasterImage *)dstImage  
                            color:(LTRasterColor *)color 
public RasterColor translateColor( 
   RasterImage destImage, 
   RasterColor color 
); 
public: 
RasterColor TranslateColor(  
   RasterImage^ destImage, 
   RasterColor color 
)  
def TranslateColor(self,destImage,color): 

Parameters

destImage
Destination RasterImage object.

color
Value that specifies the color in the image to be translated.

Return Value

The color value or the palette index of the nearest matching color in the destination image. If the destination image is 8 bits per pixel or less, this is always the palette index (The value of the RasterColor.IsPaletteIndex is true). Otherwise, it is the color value.

Remarks

When creating a target image for animation, you can use this method to ensure that the correct color is specified as the background color.

The reverse of this method (to get a true RGB color value from a palette index color), use GetTrueColorValue.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
public void TransparentColorExample() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_Transparent.gif"); 
 
	// Load the image 
	RasterImage image = codecs.Load(srcFileName); 
 
	// Change the image's palette to be Red and Blue 
	RasterColor[] redBluePalette = new RasterColor[2]; 
	redBluePalette[0] = RasterColor.FromKnownColor(RasterKnownColor.Red); 
	redBluePalette[1] = RasterColor.FromKnownColor(RasterKnownColor.Blue); 
	image.SetPalette(redBluePalette, 0, 2); 
 
	// make red the transparent color 
	image.Transparent = true; 
	image.TransparentColor = redBluePalette[0]; 
 
	// Save the image 
	codecs.Save(image, destFileName, RasterImageFormat.Gif, 8); 
 
	// Now load Ocr1_Transparent.gif in Internet Explorer. 
	// Notice how red is treated as a transparent color. 
	// You should get Blue text on a white background 
	//    (if IE's background color is white). 
 
	image.Dispose(); 
	codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.16
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.