List of usage examples for android.media ExifInterface ORIENTATION_NORMAL
int ORIENTATION_NORMAL
To view the source code for android.media ExifInterface ORIENTATION_NORMAL.
Click Source Link
From source file:Main.java
/** * Return the string representation of the given orientation * * @param orientation/*ww w . j av a2 s . c o m*/ * @return */ public static String getExifOrientation(int orientation) { switch (orientation) { case 0: return String.valueOf(ExifInterface.ORIENTATION_NORMAL); case 90: return String.valueOf(ExifInterface.ORIENTATION_ROTATE_90); case 180: return String.valueOf(ExifInterface.ORIENTATION_ROTATE_180); case 270: return String.valueOf(ExifInterface.ORIENTATION_ROTATE_270); default: throw new AssertionError("invalid: " + orientation); } }
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {//from w ww .jav a2 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 {/*from w w w. ja v a 2 s. co m*/ // 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
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 w w w .j av a 2 s . c om 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
@Nullable private static Bitmap applyExif(@NonNull Bitmap bitmap, String exifFilePath) { final int orientation = getExifOrientation(exifFilePath); if (orientation == ExifInterface.ORIENTATION_NORMAL || orientation == ExifInterface.ORIENTATION_UNDEFINED) { return bitmap; }//from www . j a v a2 s . c o m try { return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), getExifMatrix(orientation), true); } finally { bitmap.recycle(); } }
From source file:com.exzogeni.dk.graphics.Bitmaps.java
private static int getExifOrientation(String filePath) { try {/*from w w w . j a v a2s. c o m*/ return new ExifInterface(filePath).getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e) { Logger.error(e); } return ExifInterface.ORIENTATION_UNDEFINED; }
From source file:mobisocial.noteshere.util.UriImage.java
public static float rotationForImage(Context context, Uri uri) { if (uri.getScheme().equals("content")) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query(uri, projection, null, null, null); try {/*from w w w.j a v a 2 s . c o m*/ if (c.moveToFirst()) { return c.getInt(0); } } finally { c.close(); } } else if (uri.getScheme().equals("file")) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = (int) exifOrientationToDegrees( exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)); return rotation; } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return 0f; }
From source file:at.wada811.imageslider.MainActivity.java
private int getOrientationFromExif(String filePath) { try {/* w w w .j ava 2s. com*/ 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; }
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 {/*w w w.j av a 2 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:com.haru.ui.image.workers.MediaProcessorThread.java
private String compressAndSaveImage(String fileImage, int scale) throws Exception { try {// w w w .j a v a 2 s . c o m ExifInterface exif = new ExifInterface(fileImage); String width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String length = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; if (/* TODO: DEBUG */ true) { Log.i(TAG, "Before: " + width + "x" + length); } switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = -90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } int w = Integer.parseInt(width); int l = Integer.parseInt(length); int what = w > l ? w : l; Options options = new Options(); if (what > 1500) { options.inSampleSize = scale * 4; } else if (what > 1000 && what <= 1500) { options.inSampleSize = scale * 3; } else if (what > 400 && what <= 1000) { options.inSampleSize = scale * 2; } else { options.inSampleSize = scale; } if (/* TODO: DEBUG */ true) { Log.i(TAG, "Scale: " + (what / options.inSampleSize)); Log.i(TAG, "Rotate: " + rotate); } Bitmap bitmap = BitmapFactory.decodeFile(fileImage, options); File original = new File(fileImage); File file = new File((original.getParent() + File.separator + original.getName().replace(".", "_fact_" + scale + "."))); FileOutputStream stream = new FileOutputStream(file); if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); if (/* TODO: DEBUG */ true) { ExifInterface exifAfter = new ExifInterface(file.getAbsolutePath()); String widthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String lengthAfter = exifAfter.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); if (/* TODO: DEBUG */ true) { Log.i(TAG, "After: " + widthAfter + "x" + lengthAfter); } } stream.flush(); stream.close(); return file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new Exception("Corrupt or deleted file???"); } }