3

Whenever i try to capture photo in my custom camera i am not able to detect its orientation. Captured image stored in sd card and then i retrieve for preview i use ExifInterface for orientation but orientation of image always in ExifInterface.ORIENTATION_NORMAL mode whether i captured it landscape or portrait. I have tried all the things but doesn't find Any solution.

   Matrix mat = new Matrix();

    ExifInterface exif = new ExifInterface(path);
    String orientstring = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
    int orientation = orientstring != null ? Integer.parseInt(orientstring) : ExifInterface.ORIENTATION_NORMAL;
    int rotateangle = 0;
    if (orientation == ExifInterface.ORIENTATION_NORMAL){

      rotateangle = 90;
  }
    if(orientation == ExifInterface.ORIENTATION_ROTATE_90)
        rotateangle = 90;
    if(orientation == ExifInterface.ORIENTATION_ROTATE_180)
        rotateangle = 180;
    if(orientation == ExifInterface.ORIENTATION_ROTATE_270)
        rotateangle = 270;

    mat.setRotate(rotateangle, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);

    File f = new File(path);
    Bitmap bmpPic = BitmapFactory.decodeStream(new FileInputStream(f), null, null);

    int widthBmp=bmpPic.getWidth();
    int heightBmp=bmpPic.getHeight();


    if (heightBmp < widthBmp){

         bitmap = Bitmap.createBitmap(bmpPic, 0, 0, bmpPic.getWidth(), bmpPic.getHeight(), mat, true);

    }
       return bitmap;

Thanks for Help in advance.

Nitin Thakor
  • 535
  • 3
  • 15
  • [googling your title+a couple of tags](https://www.google.es/search?q=How+to+get+orientation+of+image+%2Cis+it+landscape+or+portrait+java+android&oq=How+to+get+orientation+of+image+%2Cis+it+landscape+or+portrait+java+android&aqs=chrome..69i57.3008j0j1&sourceid=chrome&ie=UTF-8): `How to get orientation of image ,is it landscape or portrait java android` usually gives some interesting links. – Jordi Castilla Nov 10 '16 at 11:16
  • i have tried all things doesn't get any sollution – Nitin Thakor Nov 10 '16 at 11:16
  • then modify your question, put the errors and stacktrace, obtained and expected result and provide a [MCVE](http://stackoverflow.com/help/mcve) – Jordi Castilla Nov 10 '16 at 11:19

0 Answers0