←Select platform

GetPaintHPalette Method

Summary
Returns a Windows palette handle corresponding to this Leadtools.RasterImage if painted on the given device context.
Syntax
C#
C++/CLI
Python
public static IntPtr GetPaintHPalette( 
   RasterImage image, 
   IntPtr hdc 
) 
public: 
static IntPtr GetPaintHPalette(  
   RasterImage^ image, 
   IntPtr hdc 
)  
def GetPaintHPalette(self,image,hdc): 

Parameters

image
The source image.

hdc
The device context object on which this Leadtools.RasterImage is painted.

Return Value

A Windows palette handle (HPALETTE). You must delete this palette with the Windows DeleteObject API after using it.

Remarks

For more information refer to RasterImage and GDI/GDI+ and Handling Palette Changes.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
 
 
// Windows API 
[DllImport("Gdi32")] 
private static extern uint GetPaletteEntries(IntPtr hpal, uint nStartIndex, uint nNumEntries, [In, Out] byte[] colors); 
 
[DllImport("Gdi32")] 
private static extern int DeleteObject(IntPtr hObject); 
 
public void GetPaintHPaletteExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"), 8, CodecsLoadByteOrder.Rgb, 1, 1); 
 
   IntPtr hpalette = RasterImagePainter.GetPaintHPalette(image, IntPtr.Zero); 
   if (hpalette != IntPtr.Zero) 
   { 
      // Show the pal 
 
      // 4 bytes for each color 
      byte[] colors = new byte[256 * 4]; 
      GetPaletteEntries(hpalette, 0, 256, colors); 
      int index = 0; 
      for (int i = 0; i < 256; i++) 
      { 
         Console.WriteLine("{0} - {1}, {2}, {3}", i, colors[index + 0], colors[index + 1], colors[index + 2]); 
         index += 4; 
      } 
 
      DeleteObject(hpalette); 
   } 
   else 
   { 
      Console.WriteLine("There is no palette"); 
   } 
 
   image.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Drawing Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.