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

asked 27 Jan, 18:23

SGumaste's gravatar image


edited 10 Mar, 14:18

Oksana%20Serdyuk's gravatar image

Oksana Serdyuk ♦♦

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.


answered 30 Jan, 09:54

Oksana%20Serdyuk's gravatar image

Oksana Serdyuk ♦♦

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");}

(30 Jan, 15:59) SGumaste

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; }

(30 Jan, 16:00) SGumaste

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

(30 Jan, 16:00) SGumaste


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.


answered 02 Feb, 13:35

Oksana%20Serdyuk's gravatar image

Oksana Serdyuk ♦♦

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 27 Jan, 18:23

Seen: 149 times

Last updated: 10 Mar, 14:18

© 2016 ABBYY. All rights Reserved. | Privacy Policy | Legal