Example usage for android.media ExifInterface TAG_ORIENTATION

List of usage examples for android.media ExifInterface TAG_ORIENTATION

Introduction

In this page you can find the example usage for android.media ExifInterface TAG_ORIENTATION.

Prototype

String TAG_ORIENTATION

To view the source code for android.media ExifInterface TAG_ORIENTATION.

Click Source Link

Document

Type is int.

Usage

From source file:Main.java

public static int readPictureDegree(String path) {
    int degree = 0;
    try {//w ww.  j  a v  a 2s.  co 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

public static int getOrientation(String path) {
    try {//from  ww w  .  ja v  a  2s .c  om
        ExifInterface exif = new ExifInterface(path);

        return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

private static Bitmap decodeExifBitmap(File file, Bitmap src) {
    try {/*from  w w  w  . j  a  v a  2  s .  c o  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

public static int readPictureDegree(String filename) {
    short degree = 0;
    try {//  ww  w. j a  va2 s.  c om
        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;//from   w w  w. j av  a  2  s  .c  o  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);/*w w w .ja v a2  s.  c  o  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

private static int getExifOrientation(String filePath) {
    try {/*from   w ww .  j a  v  a 2s .  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 {// w ww.j a  va 2 s  .  co 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  .ja  v a  2 s .  co  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;
}

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 ww  .  ja va  2 s . com
        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();
}