Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
GetPaintColors Method
See Also  Example
Leadtools Namespace > RasterImage Class : GetPaintColors Method



graphics
The graphics object on which this image is painted.
Returns a palette corresponding to this RasterImage if painted on the given graphics object.

Syntax

Visual Basic (Declaration) 
Public Function GetPaintColors( _
   ByVal graphics As Graphics _
) As RasterColor()
Visual Basic (Usage)Copy Code
Dim instance As RasterImage
Dim graphics As Graphics
Dim value() As RasterColor
 
value = instance.GetPaintColors(graphics)
C# 
public RasterColor[] GetPaintColors( 
   Graphics graphics
)
C++/CLI 
public:
array<RasterColor>^ GetPaintColors( 
   Graphics graphics
) 

Parameters

graphics
The graphics object on which this image is painted.

Return Value

An array of color for the palette

Example

Visual BasicCopy Code
Public Sub GetPaintColorsExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP", 8, CodecsLoadByteOrder.Rgb, 1, 1)

   Dim testForm As Form = New Form()
   Dim g As Graphics = testForm.CreateGraphics()

   Dim colors As RasterColor() = image.GetPaintColors(g)
   If colors Is Nothing Then
      Console.WriteLine("There is no palette")
   Else
      Dim msg As String = String.Format("There are {0} palette entries--the first entry is RGB(0x{1:x},0x{2:x},0x{3:x})", colors.Length, colors(0).R, colors(0).G, colors(0).B)
      Console.WriteLine(msg)
   End If

   g.Dispose()
   image.Dispose()
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C#Copy Code
public void GetPaintColorsExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP", 8, CodecsLoadByteOrder.Rgb, 1, 1); 
 
   Form testForm = new Form(); 
   Graphics g = testForm.CreateGraphics(); 
 
   RasterColor[] colors = image.GetPaintColors(g); 
   if(colors == null) 
      Console.WriteLine("There is no palette"); 
   else 
   { 
      string msg = String.Format("There are {0} palette entries--the first entry is RGB(0x{1:x},0x{2:x},0x{3:x})", colors.Length, colors[0].R, colors[0].G, colors[0].B); 
      Console.WriteLine(msg); 
   } 
 
   g.Dispose(); 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

For more information, refer to Color Halftone and Halftone Images.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also