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



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

Syntax

Visual Basic (Declaration)  
Public Function GetPaintPalette( _
   ByVal graphics As Graphics _
) As ColorPalette
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim graphics As Graphics
Dim value As ColorPalette
 
value = instance.GetPaintPalette(graphics)
C#  
public ColorPalette GetPaintPalette( 
   Graphics graphics
)
C++/CLI  
public:
ColorPalette GetPaintPalette( 
   Graphics graphics
) 

Parameters

graphics
The graphics object on which this RasterImage is painted.

Return Value

a GDI+ palette

Example

Visual Basic Copy Code
Public Sub GetPaintPaletteExample()
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"

   ' Load a paletteized image
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' Get the palette
   Dim btmp As New Bitmap(1, 1)
   Dim g As Graphics = Graphics.FromImage(btmp)
   Dim palette As ColorPalette = image.GetPaintPalette(g)
   g.Dispose()
   btmp.Dispose()

   Console.WriteLine("Paint palette has {0} entries", palette.Entries.Length)
   For i As Integer = 0 To palette.Entries.Length - 1
      Console.WriteLine("{0} - {1}", i, palette.Entries(i).ToString())
   Next

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

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"; 
 
   // Load a paletteized image 
   RasterImage image = codecs.Load(srcFileName); 
 
   // Get the palette 
   Bitmap btmp = new Bitmap(1, 1); 
   Graphics g = Graphics.FromImage(btmp); 
   ColorPalette palette = image.GetPaintPalette(g); 
   g.Dispose(); 
   btmp.Dispose(); 
 
   Console.WriteLine("Paint palette has {0} entries", palette.Entries.Length); 
   for(int i = 0; i < palette.Entries.Length; i++) 
      Console.WriteLine("{0} - {1}", i, palette.Entries[i].ToString()); 
 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

For more information, refer to Handling Palette Changes.

Requirements

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

See Also