LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

ToDibArray Method

Example 





Type of DIB to create.
Gets a managed buffer containing a Windows device independent bitmap (DIB) version of this image. .NET support WinRT support
Syntax
public byte[] ToDibArray( 
   RasterConvertToDibType type
)
'Declaration
 
Public Function ToDibArray( _
   ByVal type As RasterConvertToDibType _
) As Byte()
'Usage
 
Dim instance As RasterImage
Dim type As RasterConvertToDibType
Dim value() As Byte
 
value = instance.ToDibArray(type)
public byte[] ToDibArray( 
   RasterConvertToDibType type
)
 function Leadtools.RasterImage.ToDibArray( 
   type 
)
public:
array<byte>^ ToDibArray( 
   RasterConvertToDibType type
) 

Parameters

type
Type of DIB to create.

Return Value

An array of System.Byte that contains the 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.

A DIB consists of one of the following:

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.

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

This function does not support signed images.

Example
 
Public Sub ToDibArrayExample()
      Dim codecs As New RasterCodecs()

      Dim dibData() As Byte

      Using image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))
         dibData = image.ToDibArray(RasterConvertToDibType.BitmapInfoHeader)
      End Using

      Using image As RasterImage = RasterImage.FromDibArray(dibData, 0)
         codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromDibArray.bmp"), RasterImageFormat.Bmp, 0)
      End Using

      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void ToDibArrayExample()
   {
      RasterCodecs codecs = new RasterCodecs();

      byte[] dibData;

      using(RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")))
      {
         dibData = image.ToDibArray(RasterConvertToDibType.BitmapInfoHeader);
      }

      using(RasterImage image = RasterImage.FromDibArray(dibData, 0))
      {
         codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromDibArray.bmp"), RasterImageFormat.Bmp, 0);
      }

      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterImageExamples.prototype.ToDibArrayExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var dibData;

         var srcFileName = "Assets\\Image1.cmp";
         var image;
         var image2;

         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
            .then(function (img) {
               image = img;
               dibData = image.toDibArray(RasterConvertToDibType.bitmapInfoHeader);

               image2 = RasterImage.fromDibArray(dibData, 0);

               return Tools.AppLocalFolder().createFileAsync("Image1_FromDibArray.bmp")
            })
            .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create(saveFile);
               return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 0)
            })
            .then(function () {
               image2.close();
               image.close();
               codecs.close();
            });
      }
   }
}
[TestMethod]
public async Task ToDibArrayExample()
{
   RasterCodecs codecs = new RasterCodecs();
   byte[] dibData;

   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
   {
      dibData = image.ToDibArray(RasterConvertToDibType.BitmapInfoHeader);
   }

   using (RasterImage image = RasterImage.FromDibArray(dibData, 0))
   {
      StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("Image1_FromDibArray.bmp");
      ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
      await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 0);
   }

   codecs.Dispose();
}
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

RasterImage Class
RasterImage Members
FromDib(IntPtr) Method
FromDibArray Method
ToDib Method
RasterImageConverter.FromHBitmap
RasterImageConverter.ToHBitmap
ChangeFromDib Method
RasterImageConverter.ChangeFromHBitmap
ChangeToDib Method
RasterImageConverter.ChangeToHBitmap

 

 


Products | Support | Contact Us | Copyright Notices

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