←Select platform

StartFeedGetInformation Method

Summary
Initializes a file information process in which you control the input stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void StartFeedGetInformation( 
   bool totalPages, 
   int pageNumber 
) 
- (BOOL)startFeedGetInformation:(BOOL)totalPages pageNumber:(NSInteger)pageNumber error:(NSError **)error 
public FeedCallbackThunk startFeedGetInformation(boolean totalPages, int pageNumber) 
public: 
void StartFeedGetInformation(  
   bool totalPages, 
   int pageNumber 
)  
def StartFeedGetInformation(self,totalPages,pageNumber): 

Parameters

totalPages
true to query the file for total number of pages; false, otherwise.

pageNumber
1-based index to the page number to query.

Remarks

You must call the FeedGetInformation method to supply buffered data, and you must call StopFeedGetInformation when the process is complete.

This file information process is useful when receiving transmitted images, such as those on the Internet. It works the same way as the GetInformation method, except that your code supplies the image data. The file information process works as follows:

  1. You call the StartFeedGetInformation method to initialize the file information process.
  2. You create a buffer, and each time you fill it with information, you call the FeedGetInformation method, which sends the data to the file information process just as if the data were being read from a file on disk.

    If the FeedGetInformation returns true, this means the frameworks does not have enough data to get the information required; you must read more data and call the FeedGetInformation again. When FeedGetInformation returns false, the framework has gathered enough data and you can break out of the loop.

  3. At any time after calling StartFeedGetInformation, you can call CancelFeedGetInformation to gracefully abort the feed operation. This allows you to end the feed process without throwing an exception.

  4. To end the file information process, you call the StopFeedGetInformation method, which cleans up the process, and returns an instance of the CodecsImageInfo class if successful. If you call this method before enough image data is passed to gather the information, it will successfully clean up the process, but will throw an exception. You should catch the exception if the process is canceled purposely.

This method cannot be used in combination with StartRedirecting.

Specifying true for  totalPages can cause the process to be slow for files with large number of pages.

Example

This example will use feed information to get information about an image from an URL

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void FeedGetInformationExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   codecs.CancelFeedGetInformation(); 
 
   string url = @"https://www.leadtools.com/images/page_graphics/leadlogo.png"; 
 
   // Create a WebRequest for the URL 
   WebRequest request = WebRequest.Create(url); 
   request.Proxy.Credentials = CredentialCache.DefaultCredentials; 
 
   // reduce the timeout to 20 sec 
   request.Timeout = 20000; 
 
   WebResponse response = request.GetResponse(); 
 
   try 
   { 
      Stream strm = response.GetResponseStream(); 
 
      // Read chunks from the stream and feed load to the image 
      codecs.StartFeedGetInformation(true, 1); 
 
      const int bufferSize = 1024; 
      byte[] buffer = new byte[bufferSize]; 
 
      bool more; 
 
      do 
      { 
         System.Windows.Forms.Application.DoEvents(); 
 
         int read = strm.Read(buffer, 0, bufferSize); 
         Debug.WriteLine("Downloading {0} bytes", read); 
         if (read > 0) 
            more = codecs.FeedGetInformation(buffer, 0, read); 
         else 
         { 
            // no more image data in the stream 
            more = false; 
         } 
      } 
      while (more); 
   } 
   finally 
   { 
      response.Close(); 
   } 
 
   CodecsImageInfo info = codecs.StopFeedGetInformation(); 
 
   // Clean up 
   codecs.Dispose(); 
 
   // Show the information 
   Debug.WriteLine(info.ToString()); 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
public void feedGetInformationExample() throws IOException { 
   RasterCodecs codecs = new RasterCodecs(); 
   URL url = new URL("https://www.leadtools.com/images/page_graphics/leadlogo.png"); 
 
   // Create a WebRequest for the URL 
   HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
   con.setRequestMethod("GET"); 
   con.setDefaultUseCaches(true); 
 
   // reduce the timeout to 20sec 
   con.setConnectTimeout(20000); 
   con.setReadTimeout(20000); 
   con.getResponseCode(); 
 
   FeedCallbackThunk feedLoad; 
   try { 
      InputStream inputStream = con.getInputStream(); 
 
      // Read chunks from the stream and feed load to the image 
      feedLoad = codecs.startFeedGetInformation(true, 1); 
 
      final int bufferSize = 1024; 
      byte[] buffer = new byte[bufferSize]; 
 
      boolean more; 
 
      do { 
         int read = inputStream.read(buffer, 0, bufferSize); 
         System.out.println("Downloading " + read + " bytes"); 
         if (read > 0) 
            more = feedLoad.feedGetInformation(buffer, 0, read); 
         else { 
            // no more image data in the stream 
            more = false; 
         } 
      } while (more); 
   } finally { 
      con.disconnect(); 
   } 
 
   CodecsImageInfo info = feedLoad.stopFeedGetInformation(); 
 
   // Clean up 
   codecs.dispose(); 
 
   // Show the information 
   assertTrue("The URL is invalid (null)", url != null); 
   System.out.println(info.toString()); 
} 
Requirements

Target Platforms

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

Leadtools.Codecs Assembly

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