Camera Intent Image Preview Orientation









up vote
0
down vote

favorite












I take an image in Android using the following Code:



File image = new File(this.images_object_dir, loadedObjekt.getFilename());

Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_ACTIVITY_CODE);


In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.



Is there a solution for this?










share|improve this question



























    up vote
    0
    down vote

    favorite












    I take an image in Android using the following Code:



    File image = new File(this.images_object_dir, loadedObjekt.getFilename());

    Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    startActivityForResult(intent, CAMERA_ACTIVITY_CODE);


    In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.



    Is there a solution for this?










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I take an image in Android using the following Code:



      File image = new File(this.images_object_dir, loadedObjekt.getFilename());

      Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);

      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
      startActivityForResult(intent, CAMERA_ACTIVITY_CODE);


      In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.



      Is there a solution for this?










      share|improve this question















      I take an image in Android using the following Code:



      File image = new File(this.images_object_dir, loadedObjekt.getFilename());

      Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);

      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
      startActivityForResult(intent, CAMERA_ACTIVITY_CODE);


      In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.



      Is there a solution for this?







      java android android-intent camera






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 18:28









      Kling Klang

      32k156286




      32k156286










      asked Nov 10 at 15:46









      Herry

      11




      11






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.



          Your code might start any of them.




          In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro




          That is the behavior of that one camera app out of hundreds.




          On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.




          That is the behavior of that one camera app out of hundreds.



          There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.




          Is there a solution for this?




          If you wish to use ACTION_IMAGE_CAPTURE, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.



          There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.






          share|improve this answer




















          • Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
            – Alex Cohn
            Nov 12 at 14:15

















          up vote
          0
          down vote













          Use ExifInterface to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.



           BitmapFactory.Options options = new BitmapFactory.Options();
          options.inMutable = true;
          Bitmap decoded = BitmapFactory.decodeFile(filePath, options);

          if (decoded == null) return null;

          try
          ExifInterface exif = new ExifInterface(filePath);
          int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
          ExifInterface.ORIENTATION_NORMAL);
          int rotation = 0;
          if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
          rotation = 90;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
          rotation = 270;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
          rotation = 180;


          if (rotation != 0)
          Matrix matrix = new Matrix();
          matrix.postRotate(rotation);
          Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
          decoded.getHeight(), matrix, true);
          decoded.recycle();
          Runtime.getRuntime().gc();
          decoded = newBitmap;


          catch (IOException e)
          e.printStackTrace();



          If you want to use support library in order to support devices with lower API levels, use the following dependency:



          implementation 'com.android.support:exifinterface:27.1.1'


          and import android.support.media.ExifInterface






          share|improve this answer




















          • The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
            – Herry
            Nov 10 at 16:30










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240588%2fcamera-intent-image-preview-orientation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.



          Your code might start any of them.




          In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro




          That is the behavior of that one camera app out of hundreds.




          On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.




          That is the behavior of that one camera app out of hundreds.



          There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.




          Is there a solution for this?




          If you wish to use ACTION_IMAGE_CAPTURE, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.



          There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.






          share|improve this answer




















          • Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
            – Alex Cohn
            Nov 12 at 14:15














          up vote
          2
          down vote













          There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.



          Your code might start any of them.




          In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro




          That is the behavior of that one camera app out of hundreds.




          On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.




          That is the behavior of that one camera app out of hundreds.



          There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.




          Is there a solution for this?




          If you wish to use ACTION_IMAGE_CAPTURE, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.



          There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.






          share|improve this answer




















          • Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
            – Alex Cohn
            Nov 12 at 14:15












          up vote
          2
          down vote










          up vote
          2
          down vote









          There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.



          Your code might start any of them.




          In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro




          That is the behavior of that one camera app out of hundreds.




          On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.




          That is the behavior of that one camera app out of hundreds.



          There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.




          Is there a solution for this?




          If you wish to use ACTION_IMAGE_CAPTURE, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.



          There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.






          share|improve this answer












          There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.



          Your code might start any of them.




          In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro




          That is the behavior of that one camera app out of hundreds.




          On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.




          That is the behavior of that one camera app out of hundreds.



          There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.




          Is there a solution for this?




          If you wish to use ACTION_IMAGE_CAPTURE, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.



          There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 15:52









          CommonsWare

          756k13618441897




          756k13618441897











          • Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
            – Alex Cohn
            Nov 12 at 14:15
















          • Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
            – Alex Cohn
            Nov 12 at 14:15















          Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
          – Alex Cohn
          Nov 12 at 14:15




          Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
          – Alex Cohn
          Nov 12 at 14:15












          up vote
          0
          down vote













          Use ExifInterface to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.



           BitmapFactory.Options options = new BitmapFactory.Options();
          options.inMutable = true;
          Bitmap decoded = BitmapFactory.decodeFile(filePath, options);

          if (decoded == null) return null;

          try
          ExifInterface exif = new ExifInterface(filePath);
          int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
          ExifInterface.ORIENTATION_NORMAL);
          int rotation = 0;
          if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
          rotation = 90;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
          rotation = 270;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
          rotation = 180;


          if (rotation != 0)
          Matrix matrix = new Matrix();
          matrix.postRotate(rotation);
          Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
          decoded.getHeight(), matrix, true);
          decoded.recycle();
          Runtime.getRuntime().gc();
          decoded = newBitmap;


          catch (IOException e)
          e.printStackTrace();



          If you want to use support library in order to support devices with lower API levels, use the following dependency:



          implementation 'com.android.support:exifinterface:27.1.1'


          and import android.support.media.ExifInterface






          share|improve this answer




















          • The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
            – Herry
            Nov 10 at 16:30














          up vote
          0
          down vote













          Use ExifInterface to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.



           BitmapFactory.Options options = new BitmapFactory.Options();
          options.inMutable = true;
          Bitmap decoded = BitmapFactory.decodeFile(filePath, options);

          if (decoded == null) return null;

          try
          ExifInterface exif = new ExifInterface(filePath);
          int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
          ExifInterface.ORIENTATION_NORMAL);
          int rotation = 0;
          if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
          rotation = 90;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
          rotation = 270;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
          rotation = 180;


          if (rotation != 0)
          Matrix matrix = new Matrix();
          matrix.postRotate(rotation);
          Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
          decoded.getHeight(), matrix, true);
          decoded.recycle();
          Runtime.getRuntime().gc();
          decoded = newBitmap;


          catch (IOException e)
          e.printStackTrace();



          If you want to use support library in order to support devices with lower API levels, use the following dependency:



          implementation 'com.android.support:exifinterface:27.1.1'


          and import android.support.media.ExifInterface






          share|improve this answer




















          • The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
            – Herry
            Nov 10 at 16:30












          up vote
          0
          down vote










          up vote
          0
          down vote









          Use ExifInterface to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.



           BitmapFactory.Options options = new BitmapFactory.Options();
          options.inMutable = true;
          Bitmap decoded = BitmapFactory.decodeFile(filePath, options);

          if (decoded == null) return null;

          try
          ExifInterface exif = new ExifInterface(filePath);
          int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
          ExifInterface.ORIENTATION_NORMAL);
          int rotation = 0;
          if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
          rotation = 90;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
          rotation = 270;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
          rotation = 180;


          if (rotation != 0)
          Matrix matrix = new Matrix();
          matrix.postRotate(rotation);
          Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
          decoded.getHeight(), matrix, true);
          decoded.recycle();
          Runtime.getRuntime().gc();
          decoded = newBitmap;


          catch (IOException e)
          e.printStackTrace();



          If you want to use support library in order to support devices with lower API levels, use the following dependency:



          implementation 'com.android.support:exifinterface:27.1.1'


          and import android.support.media.ExifInterface






          share|improve this answer












          Use ExifInterface to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.



           BitmapFactory.Options options = new BitmapFactory.Options();
          options.inMutable = true;
          Bitmap decoded = BitmapFactory.decodeFile(filePath, options);

          if (decoded == null) return null;

          try
          ExifInterface exif = new ExifInterface(filePath);
          int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
          ExifInterface.ORIENTATION_NORMAL);
          int rotation = 0;
          if (orientation == ExifInterface.ORIENTATION_ROTATE_90)
          rotation = 90;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_270)
          rotation = 270;
          else if (orientation == ExifInterface.ORIENTATION_ROTATE_180)
          rotation = 180;


          if (rotation != 0)
          Matrix matrix = new Matrix();
          matrix.postRotate(rotation);
          Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
          decoded.getHeight(), matrix, true);
          decoded.recycle();
          Runtime.getRuntime().gc();
          decoded = newBitmap;


          catch (IOException e)
          e.printStackTrace();



          If you want to use support library in order to support devices with lower API levels, use the following dependency:



          implementation 'com.android.support:exifinterface:27.1.1'


          and import android.support.media.ExifInterface







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 15:53









          Nabin Bhandari

          8,77521534




          8,77521534











          • The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
            – Herry
            Nov 10 at 16:30
















          • The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
            – Herry
            Nov 10 at 16:30















          The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
          – Herry
          Nov 10 at 16:30




          The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
          – Herry
          Nov 10 at 16:30

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240588%2fcamera-intent-image-preview-orientation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党