LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

StartFeedLoad(Int32,CodecsLoadByteOrder,Int32,Int32) Method

Example 





Resulting image pixel depth. Valid values are:

Value Meaning
0 Keep the original file's pixel depth (Do not convert).
1 to 8 The specified bits per pixel in the resulting image.
12 12 bits per pixel in the resulting image.
16 16 bits per pixel in the resulting image.
24 24 bits per pixel in the resulting image.
32 32 bits per pixel in the resulting image.
48 48 bits per pixel in the resulting image.
64 64 bits per pixel in the resulting image.

The desired color order. Possible values are:

Value Meaning
CodecsLoadByteOrder.Rgb Red, green, and blue color order in memory
CodecsLoadByteOrder.Bgr Blue, green, and red color order in memory
CodecsLoadByteOrder.Gray 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are only supported in the Document/Medical Imaging editions.
CodecsLoadByteOrder.RgbOrGray Load the image as red, green, blue OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions
CodecsLoadByteOrder.BgrOrGray Load the image as blue, green, red OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions
CodecsLoadByteOrder.Romm ROMM order. ROMM only supports 24 and 48-bit images
CodecsLoadByteOrder.BgrOrGrayOrRomm Load the image as red, green, blue OR as a 12 or 16-bit grayscale image OR as ROMM. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions only. ROMM only supports 24 and 48-bit color images.
1-based index of the first page to load.
The 1-based index of the last page to load. Must be greater than or equal to firstPage. You can pass -1 to load from firstPage to the last page in the file.
Initializes a file-load process in which you control the input stream with specific number of pages. .NET support WinRT support
Syntax
public void StartFeedLoad( 
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int firstPage,
   int lastPage
)
'Declaration
 
Public Overloads Sub StartFeedLoad( _
   ByVal bitsPerPixel As Integer, _
   ByVal order As CodecsLoadByteOrder, _
   ByVal firstPage As Integer, _
   ByVal lastPage As Integer _
) 
'Usage
 
Dim instance As RasterCodecs
Dim bitsPerPixel As Integer
Dim order As CodecsLoadByteOrder
Dim firstPage As Integer
Dim lastPage As Integer
 
instance.StartFeedLoad(bitsPerPixel, order, firstPage, lastPage)
public void StartFeedLoad( 
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int firstPage,
   int lastPage
)
 function Leadtools.Codecs.RasterCodecs.StartFeedLoad(Int32,CodecsLoadByteOrder,Int32,Int32)( 
   bitsPerPixel ,
   order ,
   firstPage ,
   lastPage 
)
public:
void StartFeedLoad( 
   int bitsPerPixel,
   CodecsLoadByteOrder order,
   int firstPage,
   int lastPage
) 

Parameters

bitsPerPixel

Resulting image pixel depth. Valid values are:

Value Meaning
0 Keep the original file's pixel depth (Do not convert).
1 to 8 The specified bits per pixel in the resulting image.
12 12 bits per pixel in the resulting image.
16 16 bits per pixel in the resulting image.
24 24 bits per pixel in the resulting image.
32 32 bits per pixel in the resulting image.
48 48 bits per pixel in the resulting image.
64 64 bits per pixel in the resulting image.
order

The desired color order. Possible values are:

Value Meaning
CodecsLoadByteOrder.Rgb Red, green, and blue color order in memory
CodecsLoadByteOrder.Bgr Blue, green, and red color order in memory
CodecsLoadByteOrder.Gray 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are only supported in the Document/Medical Imaging editions.
CodecsLoadByteOrder.RgbOrGray Load the image as red, green, blue OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions
CodecsLoadByteOrder.BgrOrGray Load the image as blue, green, red OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions
CodecsLoadByteOrder.Romm ROMM order. ROMM only supports 24 and 48-bit images
CodecsLoadByteOrder.BgrOrGrayOrRomm Load the image as red, green, blue OR as a 12 or 16-bit grayscale image OR as ROMM. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions only. ROMM only supports 24 and 48-bit color images.
firstPage
1-based index of the first page to load.
lastPage
The 1-based index of the last page to load. Must be greater than or equal to firstPage. You can pass -1 to load from firstPage to the last page in the file.
Remarks

You must call the FeedLoad(Byte[],Int32,Int32) method to supply buffered data, and you must call StopFeedLoad when the loading is complete.

This file-load process is useful when receiving transmitted images, such as those on the Internet. It works the same way as the Load(String) or LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods, except that your code supplies the image data. The file-load process works as follows:

  1. You call the StartFeedLoad(Int32,CodecsLoadByteOrder) method to initialize the file-load process.
  2. You create a buffer, and each time you fill it with information, you call the FeedLoad(Byte[],Int32,Int32) method, which sends the data to the file-load process just as if the data were being read from a file on disk.
  3. Whenever it has enough data to do so, the file-load process behaves the same as in the Load(String) or LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods. It allocates and begins loading the image. It calls your LoadImage event handler, if one is specified, whenever it has enough data in its input buffer.

    The file-load process updates information in the Leadtools.RasterImage when it has received enough information to do so. The file-load process will make the first call to your event handler whenever this information is available.

  4. At any time after calling StartFeedLoad(Int32,CodecsLoadByteOrder), you can call CancelFeedLoad to gracefully abort the feed load operation. This allows you to end the feed load process without throwing an exception.
  5. To end the file-load process, you call the StopFeedLoad method, which cleans up the process, and returns the loaded Leadtools.RasterImage, if successful. If you call this method before supplying the complete file, it will successfully clean up the process, but will throw an exception. You should catch the exception if the load is canceled purposely.
  6. You can also call the IsFeedLoadDone property to determine whether the framework has enough data to load the pages specified in firstPage and lastPage.

CodecsLoadByteOrder.Gray is only valid for 12 and 16-bit grayscale images. Support for 12 and 16-bit grayscale images is only available in the Document/Medical Imaging editions.

This method cannot be used in combination with StartRedirecting.

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

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif")
      Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "FeedLoadMulti.tif")

      ' Load pages 2 through 5 from the file by reading chunks from the stream
      codecs.StartFeedLoad(0, CodecsLoadByteOrder.BgrOrGray, 2, 5)

      Dim fs As FileStream = File.OpenRead(srcFileName)
      Try
         Const bufferSize As Integer = 1024
         Dim buffer(bufferSize - 1) As Byte

         Dim read As Integer

         Do
            System.Windows.Forms.Application.DoEvents()

            read = fs.Read(buffer, 0, bufferSize)
            Console.WriteLine("Feeding {0} bytes", read)
            If (read > 0) Then
               codecs.FeedLoad(buffer, 0, read)
            End If
         Loop While read > 0 AndAlso Not codecs.IsFeedLoadDone
      Finally
         fs.Close()
      End Try

      Dim image As RasterImage = codecs.StopFeedLoad()
      Console.WriteLine("{0} pages loaded", image.PageCount)

      ' Save the image to disk
      codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite)
      image.Dispose()

      ' 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 FeedLoadMultiExample()
     {
         RasterCodecs codecs = new RasterCodecs();

         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Eye.gif");
         string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "FeedLoadMulti.tif");

         // Load pages 2 through 5 from the file by reading chunks from the stream
         codecs.StartFeedLoad(0, CodecsLoadByteOrder.BgrOrGray, 2, 5);

         using (FileStream fs = File.OpenRead(srcFileName))
         {
             const int bufferSize = 1024;
             byte[] buffer = new byte[bufferSize];

             int read;

             do
             {
                 System.Windows.Forms.Application.DoEvents();

                 read = fs.Read(buffer, 0, bufferSize);
                 Console.WriteLine("Feeding {0} bytes", read);
                 if (read > 0)
                     codecs.FeedLoad(buffer, 0, read);
             }
             while (read > 0 && !codecs.IsFeedLoadDone);
         }

         RasterImage image = codecs.StopFeedLoad();
         Console.WriteLine("{0} pages loaded", image.PageCount);

         // Save the image to disk
         codecs.Save(image, destFileName, RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite);
         image.Dispose();

         // Clean up
         codecs.Dispose();
     }

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

      var srcFileName = "Assets\\Eye.gif";
      var destFileName = "FeedLoadMulti.tif";
      var image ;
      // Load pages 2 through 5 from the file by reading chunks from the stream
      codecs.startFeedLoad(0, CodecsLoadByteOrder.bgrOrGray, 2, 5);

      return Tools.AppInstallFolder().getFileAsync(srcFileName).then ( function ( loadFile ) {
         return loadFile.openAsync(Windows.Storage.FileAccessMode.read)})
      .then ( function ( randomAccessStream ) {
         var bufferSize = 1024;
         var buffer = new Windows.Storage.Streams.Buffer(bufferSize);
         
         return ReadStreamAsync (randomAccessStream, buffer, bufferSize, codecs ) })
      .then ( function ( ) {

         
         image = codecs.stopFeedLoad();
         console.info(image.pageCount, " pages loaded");

         // Save the image to disk
         return Tools.AppLocalFolder().createFileAsync(destFileName)})
      .then ( function ( saveFile ) {
         return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1, 1, -1, 1, CodecsSavePageMode.overwrite)})
      .then ( function ( ) {
         image.close();

         // Clean up
         codecs.close();
      });
   }
   }
}

function ReadStreamAsync (randomAccessStream, buffer, bufferSize, codecs ) 
{

   var read;

   return randomAccessStream.readAsync(buffer, bufferSize, Windows.Storage.Streams.InputStreamOptions.none).then(function (readBuffer) {
      console.info("Feeding " + readBuffer.length + " bytes");
      if (readBuffer.length > 0)
         codecs.feedLoad(ToArray(readBuffer), 0, readBuffer.length);
      if (readBuffer.length > 0 && !codecs.isFeedLoadDone)
         return ReadStreamAsync(randomAccessStream, buffer, bufferSize, codecs)
   });
}
 
function ToArray ( buffer ) 
{
   
      uselessReader =  Windows.Storage.Streams.DataReader.fromBuffer(buffer);
      var array = new Uint8Array(buffer.length);
      uselessReader.readBytes( array );
      uselessReader.close ( );
      return array;
}
[TestMethod]
public async Task FeedLoadMultiExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Eye.gif";
   string destFileName = @"FeedLoadMulti.tif";

   // Load pages 2 through 5 from the file by reading chunks from the stream
   codecs.StartFeedLoad(0, CodecsLoadByteOrder.BgrOrGray, 2, 5);

   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (IRandomAccessStream randomAccessStream = await loadFile.OpenAsync(FileAccessMode.Read))
   {
      using (Stream memStream = randomAccessStream.AsStream())
      {
         const int bufferSize = 1024;
         byte[] buffer = new byte[bufferSize];

         int read;

         do
         {
            read = memStream.Read(buffer, 0, bufferSize);
            Debug.WriteLine("Feeding {0} bytes", read);
            if (read > 0)
               codecs.FeedLoad(buffer, 0, read);
         }
         while (read > 0 && !codecs.IsFeedLoadDone);
      }
   }

   RasterImage image = codecs.StopFeedLoad();
   Debug.WriteLine("{0} pages loaded", image.PageCount);

   // Save the image to disk
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1, 1, -1, 1, CodecsSavePageMode.Overwrite);
   image.Dispose();

   // Clean up
   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

RasterCodecs Class
RasterCodecs Members
Overload List
Loading and Saving Images
Loading and Saving Large Tiff Files
Speeding Up 1-Bit Documents
Fast File Info

 

 


Products | Support | Contact Us | Copyright Notices

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