0

I have here existing code that I need to fix because for unknown reasons, our .dll files were probably replaced.

I am having problems on using the image for OCR (Python Tesseract). Below is the how the code works:

ImageConverter ic = new ImageConverter();
byte[] imgArray = (byte[])ic.ConvertTo(image, typeof(byte[]));

I am passing the image to make it into byte[] then pass it on the API. Then the API converts the array to image:

public Bitmap ConvertToImage(byte[] arr)
{
  using (var ms = new MemoryStream(arr))
  {
      return new Bitmap(ms);
  }

}

As an example, when I use Bitmap img2 = ConvertToImage(imgArray);, it gives me the error

innerException+stacktrace+message

I only get the GDI error when I try to use the image from the converted array. But when I use the straight image file (open file dialog) there seems to be no problem. I can't really change the code, so can anyone suggest a solution? Or what's the problem when I used the array to image file?

AdorableVB
  • 1,383
  • 1
  • 13
  • 44
  • [Is this related?](https://stackoverflow.com/questions/336387/image-save-throws-a-gdi-exception-because-the-memory-stream-is-closed) – ProgrammingLlama Sep 06 '18 at 01:26
  • @John uhm, I think not. I am not saving anything, that's why I cannot find a solution for this. I am merely using the converted image, and it throws me an error. – AdorableVB Sep 06 '18 at 01:35
  • The only other related question I found was [this](https://stackoverflow.com/questions/7996484/gdi-lockbits-unlockbits-exception/13193740) - are you doing anything with threading? – ProgrammingLlama Sep 06 '18 at 01:52

0 Answers0