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



type
Type of DIB to create.
Converts this RasterImage into a Windows device independent bitmap (DIB).

Syntax

Visual Basic (Declaration)  
Public Function ToDib( _
   ByVal type As RasterConvertToDibType _
) As IntPtr
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim type As RasterConvertToDibType
Dim value As IntPtr
 
value = instance.ToDib(type)
C#  
public IntPtr ToDib( 
   RasterConvertToDibType type
)
C++/CLI  
public:
IntPtr ToDib( 
   RasterConvertToDibType type
) 

Parameters

type
Type of DIB to create.

Return Value

A handle to the Windows DIB.

Example

Visual Basic Copy Code
Public Sub ToDibExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP")

   Dim DibData As System.IntPtr
   DibData = image.ToDib(RasterConvertToDibType.BitmapInfoHeader)
   Dim destinationImage As RasterImage

   destinationImage = RasterImage.FromDib(DibData)

   codecs.Save(destinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_FROMDIB.BMP", RasterImageFormat.Bmp, 0)

   destinationImage.Dispose()
   image.Dispose()
   codecs.Dispose()
   Marshal.FreeHGlobal(DibData)
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void ToDibExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP"); 
 
   System.IntPtr DibData; 
   DibData = image.ToDib(RasterConvertToDibType.BitmapInfoHeader); 
   RasterImage destinationImage; 
 
   destinationImage = Leadtools.RasterImage.FromDib(DibData); 
 
   codecs.Save(destinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_FROMDIB.BMP", RasterImageFormat.Bmp, 0); 
 
   destinationImage.Dispose(); 
   image.Dispose(); 
   codecs.Dispose(); 
   Marshal.FreeHGlobal(DibData); 
   RasterCodecs.Shutdown(); 
}

Remarks

When this method is completed, there are two copies of the image in memory: the DIB and the original RasterImage. Freeing one will not affect the other.

This methods allocates a DIB bitmap and copies the RasterImage to the DIB.

NOTE: This method returns the data in an unmanaged buffer. The caller is repsonsible for freeing the DIB's IntPtr when it is no longer needed. You can use Marshal.FreeHGlobal.

A DIB consists of one of the following:

  • a BITMAPFILEHEADER
  • a BITMAPV4HEADER(introduced in Windows 95 and Windows NT 4.0)
  • or a BITMAPV5HEADER (introduced in Windows 2000 and Windows 98)

followed by a color table and then the bitmap data. The resulting DIB type is determined by the value of the type parameter.

The orientation of the image and color order will depend on how the image was loaded into the RasterImage.

When you no longer need the DIB, you can free it using the Windows GlobalFree function or FreeHGlobal.

For more information on DDBs and DIBs, refer to Introduction.

This function does not support signed images.

Requirements

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

See Also