Gets the true (RGB) value of the specified color based on the current image palette.
Syntax
Parameters
- color
- a RasterColor that specifies the source color
Return Value
A
RasterColor that is guaranteed to be a true color (has RGB value)
Example
This example will create transparent GIF file
Visual Basic |
Copy Code |
Public Sub CreateTransparentGifExample() 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) Dim hdc As IntPtr = image.CreateLeadDC() 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() RasterImage.DeleteLeadDC(hdc)
Dim cmd As New ColorResolutionCommand( _ ColorResolutionCommandMode.InPlace, _ 8, _ RasterByteOrder.Rgb, _ RasterDitheringMethod.None, _ ColorResolutionCommandPaletteFlags.Optimized, _ Nothing) cmd.Run(image)
Dim transparentColor As RasterColor = RasterColor.FromGdiPlusColor(Color.Magenta)
transparentColor = image.TranslateColor(image, transparentColor)
image.Transparent = True image.TransparentColor = transparentColor
RasterCodecs.Startup() Dim codecs As New RasterCodecs()
Dim fileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "TransparentEllipses.gif" codecs.Save(image, fileName, RasterImageFormat.Gif, 8)
image.Dispose() codecs.Dispose() RasterCodecs.Shutdown() End Sub |
C# |
Copy Code |
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 = image.CreateLeadDC(); 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(); RasterImage.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.FromGdiPlusColor(Color.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.Startup(); RasterCodecs codecs = new RasterCodecs(); // Save this image as GIF string fileName = LeadtoolsExamples.Common.ImagesPath.Path + "TransparentEllipses.gif"; codecs.Save(image, fileName, RasterImageFormat.Gif, 8); // Clean up image.Dispose(); codecs.Dispose(); RasterCodecs.Shutdown(); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also