Translates the specified color in the image, and returns the nearest matching color in the destination image.
Supported in Silverlight, Windows Phone 7
Syntax
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()
Dim codecs As RasterCodecs = New RasterCodecs()
' load an 8 bpp image and a 24 bpp image
Dim myImage1 As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ulay1.bmp"))
Dim myImage2 As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "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(RasterColorConverter.ToColor(myImage2.GetPixelColor(0, 0)))
Dim index As Integer = myImage2.TranslateColor(myImage1, win32Color) And &HEFFFFFF
Console.WriteLine(String.Format("Palette index: {0}", index))
myImage2.Dispose()
myImage1.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class |
C# | Copy Code |
---|
public void TranslateColorExample()
{
RasterCodecs codecs = new RasterCodecs();
// load an 8 bpp image and a 24 bpp image
RasterImage myImage1 = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ulay1.bmp"));
RasterImage myImage2 = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"));
// translate the top-left pixel of the 24 bpp image to a palette index in the first
int win32Color = ColorTranslator.ToWin32(RasterColorConverter.ToColor(myImage2.GetPixelColor(0, 0)));
int index = myImage2.TranslateColor(myImage1, win32Color) & 0x0EFFFFFF;
Console.WriteLine(string.Format("Palette index: {0}", index));
myImage2.Dispose();
myImage1.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
} |
SilverlightCSharp | Copy Code |
---|
|
SilverlightVB | Copy Code |
---|
|
Remarks
Requirements
Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7
See Also