how to use OpenImageFileFromMemory from java

  • 75 Views
  • Last Post 05 February 2018
Hyunruel Cho posted this 02 February 2018

hello,

how to use OpenImageFileFromMemory from java?

I don't know what parameter using.      

below code, It's make an error.

 

                  ByteArrayOutputStream ous = null;
                        FileInputStream ios = null;
                        try{
                            byte[] buffer = new byte[4096];
                            ous = new ByteArrayOutputStream();
                            ios = new FileInputStream(new File(input_file));
                            int read = 0;
                            while((read = ios.read(buffer)) != -1){
                                ous.write(buffer,0,read);
                            }
                           
                        }finally{
                            try {
                                if (ous != null)
                                    ous.close();
                            } catch (IOException e) {
                            }

                            try {
                                if (ios != null)
                                    ios.close();
                            } catch (IOException e) {
                            }

                        }
                       
                        engine.OpenImageFileFromMemory(ous.toByteArray(), null, pim, null);

Order By: Standard | Newest | Votes
Koen de Leijer posted this 02 February 2018

Hi

"It's make an error." => what error?

Here is somewhat the same question+answer in C# that should be easily ported to Java;
https://forum.ocrsdk.com/thread/3918-fr-engine-11-sdk-how-to-reuse-imagedocument-object-/

Best regards
Koen de Leijer

 

Krayni Anis posted this 05 February 2018

Hi Hyunruel Cho

you can use the same steps in this example (C++)

 

   char* charPath = (char*) imageFilePath;

   cv::String imagePath = cv::String(charPath);

   cv::Mat testImage;

   testImage = cv::imread(imagePath,CV_LOAD_IMAGE_COLOR);

    CSafePtr<IImageDocument> documentImage;

   CheckResult( FREngine->OpenBitmapBits( BBF_Color, testImage.cols, testImage.rows, testImage.step[0], 0, 0, (int64_t)testImage.data, 0, documentImage.GetBuffer() ) );

   CheckResult( frDocument->AddImageDocument( documentImage ) );

Close