List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_180
int ORIENTATION_ROTATE_180
To view the source code for android.media ExifInterface ORIENTATION_ROTATE_180.
Click Source Link
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {// w w w . ja va2 s. c o m ExifInterface exifInterface = new ExifInterface(path); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
private static Bitmap decodeExifBitmap(File file, Bitmap src) { try {/* ww w .ja va 2 s .c om*/ // Try to load the bitmap as a bitmap file ExifInterface exif = new ExifInterface(file.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation == ExifInterface.ORIENTATION_UNDEFINED || orientation == ExifInterface.ORIENTATION_NORMAL) { return src; } Matrix matrix = new Matrix(); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { matrix.postRotate(90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { matrix.postRotate(180); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { matrix.postRotate(270); } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { matrix.setScale(-1, 1); matrix.postTranslate(src.getWidth(), 0); } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { matrix.setScale(1, -1); matrix.postTranslate(0, src.getHeight()); } // Rotate the bitmap return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } catch (IOException e) { // Ignore } return src; }
From source file:Main.java
public static int readPictureDegree(String filename) { short degree = 0; try {//from w ww.ja v a2 s . c o m ExifInterface exifInterface = new ExifInterface(filename); int anInt = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); switch (anInt) { case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_TRANSVERSE: default: break; case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
public static int getExifOrientation(String filepath) { int degree = 0; ExifInterface exif = null;/*w w w .j ava2s .co m*/ try { exif = new ExifInterface(filepath); } catch (IOException ex) { Log.e(TAG, "cannot read exif", ex); } if (exif != null) { int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); if (orientation != -1) { // We only recognize a subset of orientation tag values. switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; } } } return degree; }
From source file:Main.java
private static int getImageRotationAngle(Uri imageUri, ContentResolver contentResolver) throws IOException { int angle = 0; Cursor cursor = contentResolver.query(imageUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);//from ww w. ja v a 2s. co m if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst(); angle = cursor.getInt(0); } cursor.close(); } else { ExifInterface exif = new ExifInterface(imageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; default: break; } } return angle; }
From source file:com.exzogeni.dk.graphics.Bitmaps.java
@NonNull private static Matrix getExifMatrix(int orientation) { final Matrix matrix = new Matrix(); if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { matrix.setRotate(180);// w w w . j a v a2 s. com } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { matrix.setRotate(90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { matrix.setRotate(-90); } return matrix; }
From source file:mobisocial.noteshere.util.UriImage.java
private static float exifOrientationToDegrees(int exifOrientation) { if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; }//w ww . j a v a2 s. co m return 0; }
From source file:com.owncloud.android.utils.BitmapUtils.java
/** * Rotate bitmap according to EXIF orientation. * Cf. http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ * @param bitmap Bitmap to be rotated/*w w w .j a v a2 s . co m*/ * @param storagePath Path to source file of bitmap. Needed for EXIF information. * @return correctly EXIF-rotated bitmap */ public static Bitmap rotateImage(final Bitmap bitmap, final String storagePath) { try { ExifInterface exifInterface = new ExifInterface(storagePath); final int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Matrix matrix = new Matrix(); // 1: nothing to do switch (orientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.postScale(-1.0f, 1.0f); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.postScale(1.0f, -1.0f); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.postRotate(-90); matrix.postScale(1.0f, -1.0f); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.postRotate(90); matrix.postScale(1.0f, -1.0f); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(270); break; } // Rotate the bitmap final Bitmap resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); if (resultBitmap != bitmap) { bitmap.recycle(); } return resultBitmap; } catch (Exception exception) { Log_OC.e("BitmapUtil", "Could not rotate the image: " + storagePath); return bitmap; } }
From source file:com.dastardlylabs.ti.ocrdroid.OcrdroidModule.java
@Kroll.method @SuppressWarnings("rawtypes") public String ocr(HashMap _config) { assert (_config != null); String dataParentPath = getTessDataDirectory().getAbsolutePath(), //= (String) _config.get("dataParent"), imagePath = StorageHelper.stripFileUri((String) _config.get("image")), language = (String) _config.get("lang"); try {// ww w. j a va2 s . co m if (!tessDataExists()) unpackTessData(); } catch (Exception e) { // catch failure and bubble up failure message and options // else continue. } Log.d(LCAT, "ocr called"); Log.d(LCAT, "Setting parent directory for tessdata as DATAPATH".replace("DATAPATH", dataParentPath /*DATA_PATH*/)); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeFile(imagePath, options); //bitmap.getConfig() try { ExifInterface exif = new ExifInterface(imagePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); Log.v(LCAT, "Orient: " + exifOrientation); 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(LCAT, "Rotation: " + rotate); if (rotate != 0) { // Getting width & 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); // tesseract req. ARGB_8888 bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); } } catch (IOException e) { Log.e(LCAT, "Rotate or coversion failed: " + e.toString()); } // ImageView iv = (ImageView) findViewById(R.id.image); // iv.setImageBitmap(bitmap); // iv.setVisibility(View.VISIBLE); Log.v(LCAT, "Before baseApi"); TessBaseAPI baseApi = new TessBaseAPI(); baseApi.setDebug(true); baseApi.init(dataParentPath /*DATA_PATH*/, language); baseApi.setImage(bitmap); //baseApi.get String recognizedText = baseApi.getUTF8Text(); baseApi.end(); Log.v(LCAT, "OCR Result: " + recognizedText); // clean up and show if (language.equalsIgnoreCase("eng")) { recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", " "); } return recognizedText.trim(); }
From source file:at.wada811.imageslider.MainActivity.java
private int getOrientationFromExif(String filePath) { try {// w ww . ja v a2s. c o m ExifInterface exifInterface = new ExifInterface(filePath); int orientationAttr = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); LogUtils.d("orientationAttr: " + orientationAttr); switch (orientationAttr) { case ExifInterface.ORIENTATION_NORMAL: return 0; case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; } } catch (IOException e) { e.printStackTrace(); } return 0; }