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



Changes a LEAD RasterImage object to a Windows Device Dependent Bitmap (DDB).

Syntax

Visual Basic (Declaration)  
Public Overloads Function ChangeToHBitmap() As IntPtr
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim value As IntPtr
 
value = instance.ChangeToHBitmap()
C#  
public IntPtr ChangeToHBitmap()
C++/CLI  
public:
IntPtr ChangeToHBitmap(); 

Return Value

A handle to the device dependent bitmap (DDB) this method creates.

Example

This example loads a RasterImage, changes it to a DDB and then changes it back to RasterImage.

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

   ' Load an image
   Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp", 24, CodecsLoadByteOrder.BgrOrGray, 1, 1)

   ' Change to DDB
   Dim hbitmap As IntPtr = image.ChangeToHBitmap()

   ' Dispose the image since it is unusable now
   image.Dispose()

   ' Change the DDB to a new LEAD RasterImage
   image = RasterImage.ChangeFromHBitmap(hbitmap, IntPtr.Zero)

   ' Save this image back to disk
   codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "Image1_ChangeToHBitmap.bmp", RasterImageFormat.Bmp, 24)

   image.Dispose()

   ' Clean up
   DeleteObject(hbitmap)
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void ChangeToHBitmapExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Load an image 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp", 24, CodecsLoadByteOrder.BgrOrGray, 1, 1); 
 
   // Change to DDB 
   IntPtr hbitmap = image.ChangeToHBitmap(); 
 
   // Dispose the image since it is unusable now 
   image.Dispose(); 
 
   // Change the DDB to a new LEAD RasterImage 
   image = RasterImage.ChangeFromHBitmap(hbitmap, IntPtr.Zero); 
 
   // Save this image back to disk 
   codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "Image1_ChangeToHBitmap.bmp", RasterImageFormat.Bmp, 24); 
 
   image.Dispose(); 
 
   // Clean up 
   DeleteObject(hbitmap); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

This method results in only one copy of the image, and it invalidates this RasterImage object. You must call Dispose after calling this method.

For more information on DDBs and DIBs, refer to Using DIBs, DDBs, and the Clipboard.

Requirements

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

See Also