LEADTOOLS GDI/GDI+ (Leadtools.Drawing assembly)
LEAD Technologies, Inc

ChangeToHBitmap(RasterImage) Method

Example 





The source image.
Changes a LEADTOOLS Leadtools.RasterImage object to a Windows Device-Dependent Bitmap (DDB).
Syntax
public static IntPtr ChangeToHBitmap( 
   RasterImage image
)
'Declaration
 
Public Overloads Shared Function ChangeToHBitmap( _
   ByVal image As RasterImage _
) As IntPtr
'Usage
 
Dim image As RasterImage
Dim value As IntPtr
 
value = RasterImageConverter.ChangeToHBitmap(image)
public static IntPtr ChangeToHBitmap( 
   RasterImage image
)
 function Leadtools.Drawing.RasterImageConverter.ChangeToHBitmap(RasterImage)( 
   image 
)
public:
static IntPtr ChangeToHBitmap( 
   RasterImage^ image
) 

Parameters

image
The source image.

Return Value

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

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

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

For more information refer to RasterImage and GDI/GDI+.

Example
For an example, refer to ChangeToHBitmap(RasterImage).
 
Public Sub ChangeToHBitmapExample()
      Dim codecs As New RasterCodecs()

      Dim hbitmap As IntPtr

      ' Load an image
      Using image As RasterImage = 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
      End Using

      ' Change the DDB to a new LEAD RasterImage
      Using image As RasterImage = 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)
      End Using

      DeleteObject(hbitmap)

      ' Clean up
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
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:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterImageConverter Class
RasterImageConverter Members
Overload List
FromHBitmap(IntPtr,IntPtr) Method
ToHBitmap(RasterImage) Method
ChangeFromHBitmap(IntPtr,IntPtr) Method
RasterImage.FromDib
RasterImage.ToDib
RasterImage.ChangeFromDib
RasterImage.ChangeToDib

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.