Leadtools Namespace > RasterImage Class : GetTrueColorValue Method |
public RasterColor GetTrueColorValue( RasterColor color )
'Declaration Public Function GetTrueColorValue( _ ByVal color As RasterColor _ ) As RasterColor
'Usage Dim instance As RasterImage Dim color As RasterColor Dim value As RasterColor value = instance.GetTrueColorValue(color)
public RasterColor GetTrueColorValue( RasterColor color )
function Leadtools.RasterImage.GetTrueColorValue( color )
public: RasterColor GetTrueColorValue( RasterColor color )
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(RasterImage,Int32).
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
public void CreateTransparentGifExample() { // Create a 24 bpp image, we will draw on it first then convert it to 8 bpp int imageWidth = 256; int imageHeight = 256; RasterImage image = new RasterImage( RasterMemoryFlags.Conventional, imageWidth, imageHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0); // Fill this image with magenta color and draw some random ellipses on top IntPtr hdc = RasterImagePainter.CreateLeadDC(image); Graphics g = Graphics.FromHdc(hdc); g.FillRectangle(Brushes.Magenta, 0, 0, imageWidth, imageHeight); const int ellipseWidth = 40; const int ellipseHeight = 40; Random r = new Random(); for(int i = 0; i < 40; i++) { int x = r.Next(imageWidth - ellipseWidth); int y = r.Next(imageHeight - ellipseHeight); Color clr = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)); Brush brush = new SolidBrush(clr); g.FillEllipse(brush, x, y, ellipseWidth, ellipseHeight); brush.Dispose(); } g.Dispose(); RasterImagePainter.DeleteLeadDC(hdc); // Convert this image to 8 bits/pixel ColorResolutionCommand cmd = new ColorResolutionCommand( ColorResolutionCommandMode.InPlace, 8, RasterByteOrder.Rgb, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null); cmd.Run(image); // Find the Magenta color and set it as the transparent color RasterColor transparentColor = 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 RasterCodecs codecs = new RasterCodecs(); // Save this image as GIF string fileName = Path.Combine(LEAD_VARS.ImagesDir,"TransparentEllipses.gif"); codecs.Save(image, fileName, RasterImageFormat.Gif, 8); // Clean up image.Dispose(); codecs.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
[TestMethod] public async Task CreateTransparentGifExample() { // Create a 24 bpp image, we will draw on it first then convert it to 8 bpp int imageWidth = 256; int imageHeight = 256; RasterImage image = new RasterImage( RasterMemoryFlags.Conventional, imageWidth, imageHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null); // Fill this image with magenta color FillCommand fillCmd = new FillCommand(RasterColorHelper.FromKnownColor(RasterKnownColor.Magenta)); fillCmd.Run(image); RasterRegionXForm xform = new RasterRegionXForm(); xform.ViewPerspective = RasterViewPerspective.TopLeft; xform.XOffset = 0; xform.YOffset = 0; xform.XScalarDenominator = 1; xform.XScalarNumerator = 1; xform.YScalarDenominator = 1; xform.YScalarNumerator = 1; image.AddRectangleToRegion(xform, LeadRectHelper.Create(0, 0, 100, 100), RasterRegionCombineMode.Set); FillCommand fillRgnCmd = new FillCommand(RasterColorHelper.FromKnownColor(RasterKnownColor.Black)); fillRgnCmd.Run(image); // Convert this image to 8 bits/pixel ColorResolutionCommand colorResCmd = new ColorResolutionCommand( ColorResolutionCommandMode.InPlace, 8, RasterByteOrder.Rgb, RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null); colorResCmd.Run(image); // Find the Magenta color and set it as the transparent color RasterColor transparentColor = RasterColorHelper.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 RasterCodecs codecs = new RasterCodecs(); // Save this image as GIF StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("TransparentEllipses.gif"); ILeadStream saveStream = LeadStreamFactory.Create(saveFile); await codecs.SaveAsync(image, saveStream, RasterImageFormat.Gif, 8); // Clean up image.Dispose(); codecs.Dispose(); }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2