|
Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.28
|
| Leadtools Namespace > RasterImage Class > TranslateColor Method : TranslateColor(RasterImage,Int32) Method |






public int TranslateColor( RasterImage destImage, int rgb )
'Declaration
Public Overloads Function TranslateColor( _ ByVal destImage As RasterImage, _ ByVal rgb As Integer _ ) As Integer
'Usage
Dim instance As RasterImage Dim destImage As RasterImage Dim rgb As Integer Dim value As Integer value = instance.TranslateColor(destImage, rgb)
public int TranslateColor( RasterImage destImage, int rgb )
- (unsigned int)translateColorRgb:(LTRasterImage *)dstImage rgb:(unsigned int)rgb
public int translateColor( RasterImage destImage, int rgb )
public: int TranslateColor( RasterImage^ destImage, int rgb )
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.
Copy Code
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Core Imports Leadtools.ImageProcessing.Color Imports Leadtools.Controls Imports Leadtools.Dicom Imports Leadtools.Drawing Imports Leadtools.Svg 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
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 TranslateColorExample() { RasterCodecs codecs = new RasterCodecs(); // load an 8 bpp image and a 24 bpp image RasterImage myImage1 = codecs.Load(Path.Combine(ImagesPath.Path, "Ulay1.bmp")); RasterImage myImage2 = codecs.Load(Path.Combine(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(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(); }
RasterImageExamples.prototype.TranslateColorExample = function ( ) { Tools.SetLicense ( ) ; with (Leadtools) { with (Leadtools.Codecs) { var codecs = new RasterCodecs(); var srcFileName1 = "Assets\\Ulay1.bmp"; var srcFileName2 = "Assets\\Sample1.cmp"; var myImage1; var myImage2; // load an 8 bpp image and a 24 bpp image return Tools.AppInstallFolder().getFileAsync(srcFileName1).then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile)) }) .then(function (img) { myImage1 = img; return Tools.AppInstallFolder().getFileAsync(srcFileName2) }) .then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile)) }) .then(function (img2) { myImage2 = img2; // translate the top-left pixel of the 24 bpp image to a palette index in the first var color = myImage2.getPixelColor(0, 0); var translatedColor = myImage2.translateColor(myImage1, color); console.info("Palette index: ", RasterColorHelper.getStringDescription(translatedColor)); myImage2.close(); myImage1.close(); codecs.close(); }); } } }
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;
public async Task TranslateColorExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName1 = @"Assets\Ulay1.bmp";
string srcFileName2 = @"Assets\Sample1.cmp";
// load an 8 bpp image and a 24 bpp image
StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName1);
RasterImage myImage1 = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName2);
RasterImage myImage2 = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
// translate the top-left pixel of the 24 bpp image to a palette index in the first
RasterColor color = myImage2.GetPixelColor(0, 0);
RasterColor translatedColor = myImage2.TranslateColor(myImage1, color);
Debug.WriteLine(string.Format("Palette index: {0}", RasterColorHelper.GetStringDescription(translatedColor)));
myImage2.Dispose();
myImage1.Dispose();
codecs.Dispose();
}