Creates a new Leadtools.RasterImage from the specified Windows Device-Dependent Bitmap (DDB).
public static Leadtools.RasterImage FromHBitmap(IntPtr hbitmap,IntPtr hpalette)
Public Overloads Shared Function FromHBitmap( _ByVal hbitmap As IntPtr, _ByVal hpalette As IntPtr _) As Leadtools.RasterImage
public:static Leadtools.RasterImage^ FromHBitmap(IntPtr hbitmap,IntPtr hpalette)
hbitmap
Handle to the Windows DDB.
hpalette
Handle to the Windows palette. This value can be IntPtr.Zero if the DDB is dependent on a device that is greater than 8 bits, or if the image will use the system palette.
The newly create Leadtools.RasterImage object.
For more information on DDBs and DIBs, refer to Using DIBs, DDBs, and the Clipboard.
For more information refer to RasterImage and GDI/GDI+.
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DrawingImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.Color<DllImport("gdi32")> _Private Shared Function CreatePalette(ByVal lplgpl As LOGPALETTE256) As IntPtrEnd Function<DllImport("gdi32")> _Private Shared Function DeleteObject(ByVal hObject As IntPtr) As BooleanEnd Function<StructLayout(LayoutKind.Sequential, Pack:=1)> _Private Class LOGPALETTE256Public palVersion As ShortPublic palNumEntries As Short<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1024)> _Public palPalEntry() As ByteEnd Class<TestMethod()> _Public Sub FromHBitmapExample()Dim codecs As New RasterCodecs()' load image as 8-bitUsing image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"), 8, CodecsLoadByteOrder.Rgb, 1, 1)Dim hbitmap As IntPtr = IntPtr.Zerohbitmap = RasterImageConverter.ToHBitmap(image)Dim colors() As RasterColorUsing btmp As New Bitmap(1, 1)Using g As Graphics = Graphics.FromImage(btmp)colors = RasterImagePainter.GetPaintColors(image, g)End UsingEnd UsingDim hPalette As IntPtr = IntPtr.ZeroIf Not IsNothing(colors) AndAlso colors.Length <= 256 ThenDim log As New LOGPALETTE256()log.palVersion = &H300log.palNumEntries = CType(colors.Length, Short)ReDim log.palPalEntry(1023)Dim index As Integer = 0For i As Integer = 0 To colors.Length - 1log.palPalEntry(index + 0) = colors(i).Rlog.palPalEntry(index + 1) = colors(i).Glog.palPalEntry(index + 2) = colors(i).Blog.palPalEntry(index + 3) = 0index = index + 4NexthPalette = CreatePalette(log)End IfUsing destinationImage As RasterImage = RasterImageConverter.FromHBitmap(hbitmap, hPalette)codecs.Save(destinationImage, Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromHBitmap.bmp"), RasterImageFormat.Bmp, 0)End UsingIf hPalette <> IntPtr.Zero ThenDeleteObject(hPalette)End IfDeleteObject(hbitmap)End Usingcodecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;[DllImport("gdi32")]private static extern IntPtr CreatePalette(LOGPALETTE256 lplgpl);[DllImport("gdi32")]private static extern bool DeleteObject(IntPtr hObject);[StructLayout(LayoutKind.Sequential, Pack = 1)]private class LOGPALETTE256{public short palVersion;public short palNumEntries;[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]public byte[] palPalEntry;}public void FromHBitmapExample(){RasterCodecs codecs = new RasterCodecs();// load image as 8-bitusing(RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"Image1.cmp"), 8, CodecsLoadByteOrder.Rgb, 1, 1)){IntPtr hbitmap = IntPtr.Zero;hbitmap = RasterImageConverter.ToHBitmap(image);RasterColor[] colors;using(Bitmap btmp = new Bitmap(1, 1)){using(Graphics g = Graphics.FromImage(btmp)){colors = RasterImagePainter.GetPaintColors(image, g);}}IntPtr hPalette = IntPtr.Zero;if(colors != null && colors.Length <= 256){LOGPALETTE256 log = new LOGPALETTE256();log.palVersion = 0x300;log.palNumEntries = (short)colors.Length;log.palPalEntry = new byte[1024];int index = 0;for(int i = 0; i < colors.Length; i++){log.palPalEntry[index++] = colors[i].R;log.palPalEntry[index++] = colors[i].G;log.palPalEntry[index++] = colors[i].B;log.palPalEntry[index++] = 0;}hPalette = CreatePalette(log);}using(RasterImage destinationImage = RasterImageConverter.FromHBitmap(hbitmap, hPalette)){codecs.Save(destinationImage,Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromHBitmap.bmp"), RasterImageFormat.Bmp, 0);}if(hPalette != IntPtr.Zero){DeleteObject(hPalette);}DeleteObject(hbitmap);}codecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
|
Products |
Support |
Feedback: FromHBitmap(IntPtr,IntPtr) 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.