Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
TranslateColor(RasterImage,Int32) Method
See Also  Example
Leadtools Namespace > RasterImage Class > TranslateColor Method : TranslateColor(RasterImage,Int32) Method



destImage
Destination RasterImage object.
rgb
Value that specifies the color in the image to be translated.
Translates the specified color in the image, and returns the nearest matching color in the destination image.

Syntax

Visual Basic (Declaration)  
Public Overloads Function TranslateColor( _
   ByVal destImage As RasterImage, _
   ByVal rgb As Integer _
) As Integer
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim destImage As RasterImage
Dim rgb As Integer
Dim value As Integer
 
value = instance.TranslateColor(destImage, rgb)
C#  
public int TranslateColor( 
   RasterImage destImage,
   int rgb
)
C++/CLI  
public:
int TranslateColor( 
   RasterImage^ destImage,
   int rgb
) 

Parameters

destImage
Destination RasterImage object.
rgb
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. Otherwise, it is the color value.

Example

Visual Basic Copy Code
Public Sub TranslateColorExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

   ' load an 8 bpp image and a 24 bpp image
   Dim myImage1 As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Ulay1.bmp")
   Dim myImage2 As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Sample1.cmp")

   ' translate the top-left pixel of the 24 bpp image to a palette index in the first
   Dim win32Color As Integer = ColorTranslator.ToWin32(myImage2.GetPixelColor(0, 0).ToGdiPlusColor())
   Dim index As Integer = myImage2.TranslateColor(myImage1, win32Color) And &HEFFFFFF
   Console.WriteLine(String.Format("Palette index: {0}", index))

   myImage2.Dispose()
   myImage1.Dispose()

   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void TranslateColorExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // load an 8 bpp image and a 24 bpp image 
   RasterImage myImage1 = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Ulay1.bmp"); 
   RasterImage myImage2 = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Sample1.cmp"); 
 
   // translate the top-left pixel of the 24 bpp image to a palette index in the first 
   int win32Color = ColorTranslator.ToWin32(myImage2.GetPixelColor(0, 0).ToGdiPlusColor()); 
   int index = myImage2.TranslateColor(myImage1, win32Color) & 0x0EFFFFFF; 
   Console.WriteLine(string.Format("Palette index: {0}", index)); 
 
   myImage2.Dispose(); 
   myImage1.Dispose(); 
 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

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.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also