←Select platform

FeedLoad(IntPtr,int) Method

Summary
Supplies unmanaged memory image data to the file-load process from a buffer that you provide.
Syntax
C#
Objective-C
C++/CLI
Python
public void FeedLoad( 
   IntPtr data, 
   int length 
) 
- (BOOL)feedLoad:(const unsigned char *)buffer length:(NSUInteger)length error:(NSError **)error 
- (BOOL)feedLoadData:(NSData *)data length:(NSUInteger)length error:(NSError **)error 
public: 
void FeedLoad(  
   IntPtr data, 
   int length 
)  
def FeedLoad(self,data,length): 

Parameters

data
The image file unmanaged memory data.

length
Total size (in bytes) of the image data.

Remarks

Use this method with the StartFeedLoad and StopFeedLoad methods.

For a description of how the methods relate to each other, refer to StartFeedLoad.

LEADTOOLS will attempt to load corrupted files so you can see at least a portion of the image. For these images, the load methods succeed, but LoadStatus will return an error code.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void FeedLoadExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   codecs.CancelFeedLoad(); 
 
   string url = @"https://www.leadtools.com/images/page_graphics/leadlogo.png"; 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "FeedLoad.bmp"); 
 
   // Create a WebRequest for the URL 
   WebRequest request = WebRequest.Create(url); 
   request.Proxy.Credentials = CredentialCache.DefaultCredentials; 
 
   // reduce the timeout to 20sec 
   request.Timeout = 20000; 
 
   WebResponse response = request.GetResponse(); 
   try 
   { 
      Stream strm = response.GetResponseStream(); 
 
      // Read chunks from the stream and feed load to the image 
      codecs.StartFeedLoad(0, CodecsLoadByteOrder.BgrOrGray); 
 
      const int bufferSize = 1024; 
      byte[] buffer = new byte[bufferSize]; 
 
      int read; 
 
      do 
      { 
         System.Windows.Forms.Application.DoEvents(); 
 
         read = strm.Read(buffer, 0, bufferSize); 
         Debug.WriteLine("Downloading {0} bytes", read); 
         if (read > 0) 
            codecs.FeedLoad(buffer, 0, read); 
      } 
      while (read > 0); 
   } 
   finally 
   { 
      response.Close(); 
   } 
 
   RasterImage image = codecs.StopFeedLoad(); 
 
   // Save the image to disk 
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
   image.Dispose(); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
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 feedLoadExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
 
   URL url = new URL("https://www.leadtools.com/images/page_graphics/leadlogo.png"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "FeedLoad.bmp"); 
 
   // 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 requestInput = con.getInputStream(); 
 
      // Read chunks from the stream and feed load to the image 
      feedLoad = codecs.startFeedLoad(0, CodecsLoadByteOrder.BGR_OR_GRAY); 
 
      final int bufferSize = 1024; 
      byte[] buffer = new byte[bufferSize]; 
 
      int read; 
      do { 
         read = requestInput.read(buffer, 0, bufferSize); 
         System.out.println("Downloading " + read + " bytes"); 
         if (read > 0) 
            feedLoad.feedLoad(buffer, 0, read); 
      } while (read > 0); 
      requestInput.close(); 
   } finally { 
      con.disconnect(); 
   } 
 
   RasterImage image = feedLoad.stopFeedLoad(); 
 
   // Save the image to disk 
   codecs.save(image, destFileName, RasterImageFormat.BMP, 24); 
   assertTrue("Image unsuccessfully saved", (new File(destFileName)).exists()); 
   System.out.println("Saved image at" + destFileName); 
 
   // Clean up 
   image.dispose(); 
   codecs.dispose(); 
} 
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.