title: Tesseract based OCR app shows failed to read bitmap error
body: <p>I am developing an Android Application in which i would like to capture a image and extract text from that .I used tessaract library. I put a image  in drawable folder and checked it works fine but when it comes to scanning a captured image an application closing.Here is my code</p>
  <pre><code>     public class MainActivity extends AppCompatActivity {
             EditText editText;
             ImageView imageView;
             Uri outuri;
           File imgdir;
          private static final int CAMERA_REQUEST = 1888;
         Bitmap bitmap;
         File imagename;
         private TessBaseAPI vinodtessbaseapi;
         // String lang = &quot;eng&quot;;
          String path;
          File DATA_PATH;
  
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          editText = (EditText) findViewById(R.id.editText);
          imageView = (ImageView) findViewById(R.id.imageView);
          path = Environment.getExternalStorageDirectory().toString()+&quot;/VinodOCR&quot;;
         // path = getFilesDir()+&quot;/VinodOCR/tessdata&quot;;
          checkFile(new File(path+&quot;tessdata/&quot;));
          String lang = &quot;eng&quot;;
          vinodtessbaseapi = new TessBaseAPI();
          vinodtessbaseapi.init(path,lang);
  
      }
  
      public void imageok(View view) {
          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          String timestamp = new SimpleDateFormat(&quot;yyyyMMdd_HHmmss&quot;).format(new Date());
          imgdir = new File(Environment.getExternalStorageDirectory().toString(), &quot;VinodOCR/imgs&quot;);
          imgdir.mkdirs();
          imagename = new File(imgdir, &quot;Vinod_&quot; + timestamp + &quot;.jpg&quot;);
          outuri = Uri.fromFile(imagename);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri);
          startActivityForResult(intent, 1);
          Toast.makeText(this, &quot;Image saved in directory&quot;,     Toast.LENGTH_LONG).show();
      }
  
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == CAMERA_REQUEST &amp;&amp; resultCode == Activity.RESULT_OK) {
              onPhotoTaken();
          }
  
      }
  
      protected void onPhotoTaken() {
  
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inPreferredConfig = Bitmap.Config.ARGB_8888;
          options.inSampleSize = 4;
  
          bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+&quot;/VinodOCR/imgs&quot;+imagename, options);
  
          try {
              ExifInterface exif = new ExifInterface(String.valueOf(Environment.getExternalStorageDirectory()+&quot;/VinodOCR/imgs&quot;+imagename));
              int exifOrientation = exif.getAttributeInt(
                      ExifInterface.TAG_ORIENTATION,
                      ExifInterface.ORIENTATION_NORMAL);
  
  
              Toast.makeText(this, &quot;Orient&quot;, Toast.LENGTH_LONG).show();
              int rotate = 0;
  
              switch (exifOrientation) {
                  case ExifInterface.ORIENTATION_ROTATE_90:
                      rotate = 90;
                      break;
                  case ExifInterface.ORIENTATION_ROTATE_180:
                      rotate = 180;
                      break;
                  case ExifInterface.ORIENTATION_ROTATE_270:
                      rotate = 270;
                      break;
              }
  
              // Log.v(TAG, &quot;Rotation: &quot; + rotate);
  
              if (rotate != 0) {
  
                  // Getting width &amp; height of the given image.
                  int w = bitmap.getWidth();
                  int h = bitmap.getHeight();
  
                  // Setting pre rotate
                  Matrix mtx = new Matrix();
                  mtx.preRotate(rotate);
  
                  // Rotating Bitmap
                  bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
              }
  
              // Convert to ARGB_8888, required by tess
              bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
  
          } catch (IOException e) {
              Toast.makeText(this, &quot;Couldn't correct orientation:&quot; + e.toString(), Toast.LENGTH_LONG).show();
          }
      }
      private  void  checkFile(File dir){
          if(!dir.exists()&amp;&amp;dir.mkdirs()){
              copyFile();
  
          }
          if(dir.exists()){
              String dfpath = DATA_PATH+&quot;/tessdata/eng.traineddata&quot;;
              File datafile = new File(dfpath);
              if(!datafile.exists()){
                  copyFile();
              }
          }
      }
  
      private void copyFile(){
          try {
              String filepath = DATA_PATH+&quot;/tessdata/eng.traineddata&quot;;
              AssetManager assetManager = getAssets();
              InputStream inputStream = assetManager.open(&quot;tessdata/eng.traineddata&quot;);
              OutputStream outputStream = new FileOutputStream(filepath);
              byte[] buffer = new byte[1024];
              int reads;
              while ((reads = inputStream.read(buffer))!= -1){
                  outputStream.write(buffer,0,reads);
              }
              outputStream.flush();
              outputStream.close();
              inputStream.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
      public void processImage(View view){
          vinodtessbaseapi.setImage(bitmap);
          String OCRResult = vinodtessbaseapi.getUTF8Text();
        //  TextView ocrtextview = (TextView)findViewById(R.id.OCRTextView);
          editText.setText(OCRResult);
      }
  
  
  }
  </code></pre>
  <p>I am attaching the error log also. Kindly please help me to get rid of this error:</p>
  <p><a href="https://i.stack.imgur.com/y1hoZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y1hoZ.png" alt="enter image description here" /></a></p>