image as byte array custom image source Fine Reader 11

  • Last Post 30 January 2017
SGumaste posted this 27 January 2017

Is there any way to add images as byte[] to the FREngine.IEngine for OCR processing rather than giving the path of image file to the "AddImageFile" method of FREngine.FRDocument object?.

this is for Windows web service, .NET

Order By: Standard | Newest | Votes
Oksana Serdyuk posted this 30 January 2017

Please consider using the IFRDocument::AddImageFileFromStream method. This method opens an image file from the input stream implemented by the user, and adds the pages corresponding to the opened file to the document. For more information about this method please refer to the Help file: API Reference→Document-Related Objects→Document Organization Objects→FRDocument Object, section "Methods" and API Reference→Supplementary Objects→IReadStream.

SGumaste posted this 30 January 2017

Hi Oksnana, I did try using IReadStream but no luck, program goes into infinite loop. Definitely I am doing something wrong, I am pasting my code here can you please help me : am breaking into two comments because of chars restrictions public void foo() {FREngine.IEngine engine = _enginesPool.GetEngine(); FREngine.FRDocument frDocument = engine.CreateFRDocument(); byte[] myBytes = File.ReadAllBytes(argImagesPath); CustomReadStream crs = new CustomReadStream(myBytes); frDocument.AddImageFileFromStream(crs, null, null, null, "0");}

SGumaste posted this 30 January 2017

class CustomReadStream : IReadStream { public CustomReadStream(byte[] argImageBytes) {currentPos = 0; imageBytes = new byte[argImageBytes.Length]; argImageBytes.CopyTo(imageBytes, 0);} public int Read(out Array data, int count) { data = imageBytes; buf = new byte[imageBytes.Length]; imageBytes.CopyTo(buf, 0); return imageBytes.Length; }

SGumaste posted this 30 January 2017

public void Close() { imageBytes = null; buf = null; } uint currentPos = 0; byte[] imageBytes = null; byte[] buf = null; }

Oksana Serdyuk posted this 02 February 2017


Please sorry for the delay!

First of all, please check what FineReader Engine release you use. The case is that the implementation of the IReadStream interface was changed in our Help file to more optimal beginning from the 5th release of the program, the build number - And now the current version of FineReader Engine 11 is the 8th release, the build number - Please contact your Sales Manager to update your FineReader Engine package.

Below please find our sample C# code snippet illustrating how to implement the IReadStream interface and use the IFRDocument::AddImageFileFromStream() method:

// ...
using System.IO; 
// ...

class CustomReadStream : FREngine.IReadStream
    private MemoryStream fileBytes = null;

    public CustomReadStream(byte[] _fileBytes)
        fileBytes = new MemoryStream(_fileBytes);

    public void Close()

    public int Read(out byte[] data, int count)
        data = new byte[count];
        int readBytes = fileBytes.Read(data, 0, count);
        return readBytes;

// ...

// Create document
FREngine.FRDocument document = engineLoader.Engine.CreateFRDocument();

// Add image file to document  
byte[] myBytes = File.ReadAllBytes(imagePath);
CustomReadStream readStream = new CustomReadStream(myBytes);
document.AddImageFileFromStream(readStream, null, null, null, "0");

Then you can continue processing using the FRDocument object in the way you prefer.