Leadtools.Codecs Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.17
EncodeAbic Method
See Also  Example
Leadtools.Codecs Namespace > RasterCodecs Class : EncodeAbic Method




Encodes the input raw data using the ABIC encoder.

Overload List

OverloadDescription
EncodeAbic(Byte[],Int32,Int32,Int32,Boolean) Encodes the input raw data using the ABIC encoder.  
EncodeAbic(RasterNativeBuffer,Int32,Int32,Int32,Boolean) Encodes the input raw unmanaged memory data using the ABIC encoder.  

Example

Visual BasicCopy Code
RasterCodecs.Abic
      Public Sub EncodeDecodeAbicExample()
         RasterCodecs.Startup()
         Dim codecs As RasterCodecs = New RasterCodecs()

         Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"
         Dim destDataFile As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_Abic.bmp"

         ' Load the file save it to a memory stream as RAW
         Console.WriteLine("Loading the source image as 1 bits/pixel")
         Dim srcImage As RasterImage = codecs.Load(srcFileName, 1, CodecsLoadByteOrder.Rgb, 1, 1)

         Console.WriteLine("Saving the image to memory as RAW format")
         Dim ms As MemoryStream = New MemoryStream()
         codecs.Save(srcImage, ms, RasterImageFormat.Raw, srcImage.BitsPerPixel)

         Console.WriteLine("Encoding the data as ABIC")
         Dim rawData As Byte() = ms.GetBuffer()
         ms.Close()

         ' Encode this data as ABIC
         Dim abicData As Byte() = codecs.EncodeAbic(rawData, 4, srcImage.Width, srcImage.Height, False)

         ' Decode the data back to RAW
         Console.WriteLine("Deconding the data back as RAW")
         rawData = codecs.DecodeAbic(abicData, 4, srcImage.Width, srcImage.Height, False)

         ' Create a new image from this data
         Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0)

         ' Add the scan lines
         Dim y As Integer = 0
         Do While y < destImage.Height
            Dim bufferIndex As Integer = y * destImage.BytesPerLine
            destImage.SetRow(y, rawData, bufferIndex, destImage.BytesPerLine)
            y += 1
         Loop

         ' Save this image to disk
         codecs.Save(destImage, destDataFile, RasterImageFormat.Bmp, destImage.BitsPerPixel)

         srcImage.Dispose()
         destImage.Dispose()

         ' Clean up
         codecs.Dispose()
         RasterCodecs.Shutdown()
      End Sub
C#Copy Code
RasterCodecs.Abic 
      public void EncodeDecodeAbicExample() 
      { 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
 
         string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; 
         string destDataFile = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_Abic.bmp"; 
 
         // Load the file save it to a memory stream as RAW 
         Console.WriteLine("Loading the source image as 1 bits/pixel"); 
         RasterImage srcImage = codecs.Load(srcFileName, 1, CodecsLoadByteOrder.Rgb, 1, 1); 
 
         Console.WriteLine("Saving the image to memory as RAW format"); 
         MemoryStream ms = new MemoryStream(); 
         codecs.Save(srcImage, ms, RasterImageFormat.Raw, srcImage.BitsPerPixel); 
 
         Console.WriteLine("Encoding the data as ABIC"); 
         byte[] rawData = ms.GetBuffer(); 
         ms.Close(); 
 
         // Encode this data as ABIC 
         byte[] abicData = codecs.EncodeAbic(rawData, 4, srcImage.Width, srcImage.Height, false); 
 
         // Decode the data back to RAW 
         Console.WriteLine("Deconding the data back as RAW"); 
         rawData = codecs.DecodeAbic(abicData, 4, srcImage.Width, srcImage.Height, false); 
 
         // Create a new image from this data 
         RasterImage destImage = new RasterImage( 
            RasterMemoryFlags.Conventional, 
            srcImage.Width, 
            srcImage.Height, 
            srcImage.BitsPerPixel, 
            srcImage.Order, 
            srcImage.ViewPerspective, 
            srcImage.GetPalette(), 
            IntPtr.Zero, 
            0); 
 
         // Add the scan lines 
         for(int y = 0; y < destImage.Height; y++) 
         { 
            int bufferIndex = y * destImage.BytesPerLine; 
            destImage.SetRow(y, rawData, bufferIndex, destImage.BytesPerLine); 
         } 
 
         // Save this image to disk 
         codecs.Save(destImage, destDataFile, RasterImageFormat.Bmp, destImage.BitsPerPixel); 
 
         srcImage.Dispose(); 
         destImage.Dispose(); 
 
         // Clean up 
         codecs.Dispose(); 
         RasterCodecs.Shutdown(); 
      }

Remarks

Call this method to compress the input raw data to 1-bit bi-level or 4-bit grayscale ABIC data.

Use DecodeAbic to decode ABIC data.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also