←Select platform

ChangeFromHBitmap(IntPtr,IntPtr) Method

Summary
Changes a Windows Device-Dependent Bitmap (DDB) to a LEADTOOLS Leadtools.RasterImage object.
Syntax
C#
C++/CLI
Python
public static RasterImage ChangeFromHBitmap( 
   IntPtr hbitmap, 
   IntPtr hpalette 
) 
public: 
static RasterImage^ ChangeFromHBitmap(  
   IntPtr hbitmap, 
   IntPtr hpalette 
)  
def ChangeFromHBitmap(self,hbitmap,hpalette): 

Parameters

hbitmap
Handle to the DDB to be changed.

hpalette
Handle to the palette. This value can be IntPtr.Zero if the  hbitmap parameter refers to a bitmap that is greater than 8 bits, or if the bitmap will use the system palette.

Return Value

The newly created Leadtools.RasterImage object.

Remarks

This method results in only one copy of the image, and it invalidates the DDB (hbitmap) handle.

For more information on DDBs, DIBs, GDI and GDI+ refer to Using DIBs, DDBs, and the Clipboard and RasterImage and GDI/GDI+.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public void ChangeToHBitmapExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   IntPtr hbitmap; 
 
   // Load an image 
   using (RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"), 24, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
   { 
      // Change to DDB 
      hbitmap = RasterImageConverter.ChangeToHBitmap(image); 
 
      // Dispose the image since it is unusable now 
   } 
 
   // Change the DDB to a new LEAD RasterImage 
   using (RasterImage image = RasterImageConverter.ChangeFromHBitmap(hbitmap, IntPtr.Zero)) 
   { 
      // Save this image back to disk 
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_ChangeToHBitmap.bmp"), RasterImageFormat.Bmp, 24); 
   } 
 
   DeleteObject(hbitmap); 
 
   // Clean up 
   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.