←Select platform

ToDib Method

Summary
Gets an unmanaged pointer containing a Windows Device Independent Bitmap (DIB) version of this image.
Syntax
C#
Objective-C
C++/CLI
Python
public IntPtr ToDib( 
   RasterConvertToDibType type 
) 
- (nullable LTHandle *)toDib:(LTRasterConvertToDibType)type 
public: 
IntPtr ToDib(  
   RasterConvertToDibType type 
)  
def ToDib(self,type): 

Parameters

type
Type of DIB to create.

Return Value

A handle to the Windows DIB.

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 responsible 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: DIBs, DDBs, and the Clipboard.

This function does not support signed images.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
public void ToDibExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   IntPtr dib; 
 
   using (RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))) 
   { 
      dib = image.ToDib(RasterConvertToDibType.BitmapInfoHeader); 
   } 
 
   using (RasterImage image = RasterImage.FromDib(dib)) 
   { 
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromDib.bmp"), RasterImageFormat.Bmp, 0); 
   } 
 
   Marshal.FreeHGlobal(dib); 
 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.