Returns a Windows palette handle corresponding to this Leadtools.RasterImage if painted on the given device context.
public static IntPtr GetPaintHPalette(
Leadtools.RasterImage image,
IntPtr hdc
)
Public Shared Function GetPaintHPalette( _
ByVal image As Leadtools.RasterImage, _
ByVal hdc As IntPtr _
) As IntPtr
public:
static IntPtr GetPaintHPalette(
Leadtools.RasterImage^ image,
IntPtr hdc
)
image
The source image.
hdc
The device context object on which this Leadtools.RasterImage is painted.
A Windows palette handle (HPALETTE). You must delete this palette with the Windows DeleteObject API after using it.
For more information refer to RasterImage and GDI/GDI+.
For more information, refer to Handling Palette Changes.
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
' Windows API
<DllImport("Gdi32")> _
Private Shared Function GetPaletteEntries(ByVal hpal As IntPtr, ByVal nStartIndex As UInt32, ByVal nNumEntries As UInt32, <InAttribute(), Out()> ByVal colors() As Byte) As UInt32
End Function
<DllImport("Gdi32")> _
Private Shared Function DeleteObject(ByVal hObject As IntPtr) As Integer
End Function
<TestMethod()> _
Public Sub GetPaintHPaletteExample()
Dim codecs As New RasterCodecs()
Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"), 8, CodecsLoadByteOrder.Rgb, 1, 1)
Dim hpalette As IntPtr = RasterImagePainter.GetPaintHPalette(image, IntPtr.Zero)
If hpalette <> IntPtr.Zero Then
' Show the pal
' 4 bytes for each color
Dim colors(256 * 4 - 1) As Byte
GetPaletteEntries(hpalette, 0, 256, colors)
Dim index As Integer = 0
For i As Integer = 0 To 255
Console.WriteLine("{0} - {1}, {2}, {3}", i, colors(index + 0), colors(index + 1), colors(index + 2))
index = index + 4
Next
DeleteObject(hpalette)
Else
Console.WriteLine("There is no palette")
End If
image.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
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:\Users\Public\Documents\LEADTOOLS Images";
}
Products |
Support |
Feedback: GetPaintHPalette Method - Leadtools.Drawing |
Introduction |
Help Version 19.0.2017.3.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.