←Select platform

GetTrueColorValue Method

Summary

Gets the true (RGB) value of the specified color based on the current image palette.

Syntax

C#
VB
Java
Objective-C
WinRT C#
C++
public RasterColor GetTrueColorValue( 
   RasterColor color 
) 
Public Function GetTrueColorValue( _ 
   ByVal color As Leadtools.RasterColor _ 
) As Leadtools.RasterColor 
- (LTRasterColor *)getTrueColorValue:(LTRasterColor *)color 
public RasterColor getTrueColorValue(RasterColor color) 
 function Leadtools.RasterImage.GetTrueColorValue(  
   color  
) 
public: 
Leadtools.RasterColor GetTrueColorValue(  
   Leadtools.RasterColor color 
)  

Parameters

color
a RasterColor that specifies the source color

Return Value

A RasterColor that is guaranteed to be a true color (has RGB value)

Remarks

Use this method to translate a color that is really a palette index (the value of the RasterColor.IsPaletteIndex property is true) to a true RGB color value

The apposite of this method is TranslateColor.

Example

This example will create transparent GIF file

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Drawing; 
using LeadtoolsExamples.Common; 
 
public void CreateTransparentGifExample() 
{ 
   // Create a 24 bpp image, we will draw on it first then convert it to 8 bpp 
   using (RasterImage image = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      256, 
      256, 
      8, 
      RasterByteOrder.Bgr, 
      RasterViewPerspective.BottomLeft, 
      null, 
      IntPtr.Zero, 
      0)) 
   { 
      Assert.IsNotNull(image); 
 
      // Fill the image with the transparent color. 
      RasterColor transparentColor = RasterColor.FromKnownColor(RasterKnownColor.Magenta); 
      new FillCommand(transparentColor).Run(image); 
 
      image.Transparent = true; 
      // Get the true color used for Magenta inside this image (a palette index) 
      image.TransparentColor = image.TranslateColor(image, transparentColor); 
 
      // Draw on the image, else the entire image will be transparent. 
      DrawEllipses(image); 
 
      // Save this image as GIF 
      string fileName = Path.Combine(ImagesPath.Path, "TransparentEllipses.gif"); 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         codecs.Save(image, fileName, RasterImageFormat.Gif, 8); 
      } 
   } 
} 
 
void DrawEllipses(RasterImage image) 
{ 
   // Fill this image with magenta color and draw some random ellipses on top 
   const int ellipseWidth = 40; 
   const int ellipseHeight = 40; 
   IntPtr hdc = IntPtr.Zero; 
   try 
   { 
      hdc = RasterImagePainter.CreateLeadDC(image); 
      Assert.IsFalse(hdc == IntPtr.Zero); 
 
      using (Graphics g = Graphics.FromHdc(hdc)) 
      { 
         Assert.IsNotNull(g); 
         Random r = new Random(); 
         for (int i = 0; i < 40; i++) 
         { 
            int x = r.Next(image.Width - ellipseWidth); 
            int y = r.Next(image.Height - ellipseHeight); 
            Color clr = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)); 
            using (Brush brush = new SolidBrush(clr)) 
            { 
               g.FillEllipse(brush, x, y, ellipseWidth, ellipseHeight); 
            } 
         } 
      } 
   } 
   finally 
   { 
      // Make sure to delete the handle to the DC. 
      if (hdc != IntPtr.Zero) 
         RasterImagePainter.DeleteLeadDC(hdc); 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Drawing 
 
Public Sub CreateTransparentGifExample() 
   ' Create a 24 bpp image, we will draw on it first then convert it to 8 bpp 
   Dim imageWidth As Integer = 256 
   Dim imageHeight As Integer = 256 
   Dim image As New RasterImage( 
      RasterMemoryFlags.Conventional, 
      imageWidth, 
      imageHeight, 
      24, 
      RasterByteOrder.Bgr, 
      RasterViewPerspective.BottomLeft, 
      Nothing, 
      IntPtr.Zero, 
      0) 
 
   ' Fill this image with magenta color and draw some random ellipses on top 
   Dim hdc As IntPtr = RasterImagePainter.CreateLeadDC(image) 
   Dim g As Graphics = Graphics.FromHdc(hdc) 
 
   g.FillRectangle(Brushes.Magenta, 0, 0, imageWidth, imageHeight) 
 
   Const ellipseWidth As Integer = 40 
   Const ellipseHeight As Integer = 40 
 
   Dim r As New Random() 
 
   For i As Integer = 0 To 39 
      Dim x As Integer = r.Next(imageWidth - ellipseWidth) 
      Dim y As Integer = r.Next(imageHeight - ellipseHeight) 
 
      Dim clr As Color = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)) 
      Dim brush As New SolidBrush(clr) 
      g.FillEllipse(brush, x, y, ellipseWidth, ellipseHeight) 
      brush.Dispose() 
   Next 
 
   g.Dispose() 
   RasterImagePainter.DeleteLeadDC(hdc) 
 
   ' Convert this image to 8 bits/pixel 
   Dim cmd As New ColorResolutionCommand( 
      ColorResolutionCommandMode.InPlace, 
      8, 
      RasterByteOrder.Rgb, 
      RasterDitheringMethod.None, 
      ColorResolutionCommandPaletteFlags.Optimized, 
      Nothing) 
   cmd.Run(image) 
 
   ' Find the Magenta color and set it as the transparent color 
   Dim transparentColor As RasterColor = RasterColor.FromKnownColor(RasterKnownColor.Magenta) 
 
   ' Get the true color used for Magenta inside this image (a palette index) 
   transparentColor = image.TranslateColor(image, transparentColor) 
 
   image.Transparent = True 
   image.TransparentColor = transparentColor 
 
   ' Initialize the RasterCodecs object 
   Dim codecs As New RasterCodecs() 
 
   ' Save this image as GIF 
   Dim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "TransparentEllipses.gif") 
   codecs.Save(image, fileName, RasterImageFormat.Gif, 8) 
 
   ' Clean up 
   image.Dispose() 
   codecs.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.19
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly