Tuesday, January 31, 2017

Handle image orientation with custom camera activity - Android

 ExifInterface exif = new ExifInterface(_path);  
 int exifOrientation = exif.getAttributeInt(  
  ExifInterface.TAG_ORIENTATION,  
  ExifInterface.ORIENTATION_NORMAL);  
 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;  
 }  
 if (rotate != 0) {  
  int w = bitmap.getWidth();  
  int h = bitmap.getHeight();  
  // Setting pre rotate  
  Matrix mtx = new Matrix();  
  mtx.preRotate(rotate);  
  // Rotating Bitmap & convert to ARGB_8888, required by tess  
  bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);  
  bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);  
 }  

No comments :

Post a Comment