question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Image rotated 90 degrees

See original GitHub issue

I am using ImagePicker.showImagePicker to take a photo. iOS outputs a correctly orientated image. On Android, the image is rotated 90 degrees. I am taking a picture using a Google Pixel API 25 Simulator. The simulator is in portrait mode.

This is the relevant part of response

{
  height: 480,
  isVertical: true,
  originalRotation: 0,
  width: 640
}

isVertical: true but the height and width are switched (so rotated 90 degrees).

Related #199 #388

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:25
  • Comments:30 (1 by maintainers)

github_iconTop GitHub Comments

100reactions
hubertli1991commented, Aug 31, 2018

Hope this helps. Setting rotation: 360 worked for me.

Image-picker’s “original” / default image config causes this bug.

Overriding the default config is not so straight forward because this library ignores some image configurations. https://github.com/react-community/react-native-image-picker/blob/694fa1de5cf4a3dce8e135054c3831fba85e3880/android/src/main/java/com/imagepicker/media/ImageConfig.java#L139

So, if you only set rotation: 0, the image on Android will get rotated 90 degrees because image-picker will continue to use the default image config. If, however, you set rotation: nonZeroInteger, image-picker will respect your configuration – setting rotation to 360 will preserve the orientation. If you don’t set rotation and just set quality: 0.99 (I would not suggest doing this), image-picker will also respect your config – not rotate and reduce the quality by 0.01.

47reactions
Monte9commented, Nov 21, 2017

@JonoH your solution works for me. Although one thing to note is that when taking images with the front camera (selfie), the rotation is 270.

Hence here is what I ended up with in case it helps someone: (react-native-image-picker + react-native-image-resizer)

const IMAGE_PICKER_OPTIONS = {
  title: 'Select a photo',
  mediaType: 'photo',
  noData: true
}

ImagePicker.launchCamera( IMAGE_PICKER_OPTIONS, response => {
  const { error, uri, originalRotation } = response

  if ( uri && !error ) {
    let rotation = 0

    if ( originalRotation === 90 ) {
      rotation = 90
    } else if ( originalRotation === 270 ) {
      rotation = -90
    }

    ImageResizer.createResizedImage( uri, 800, 600, "JPEG", 80, rotation ).
      then( ( { uri } ) => {
        this.setState( { uri } )
      } ).catch( err => {
        console.log( err )

        return Alert.alert( 'Unable to resize the photo', 'Please try again!' )
      } )
  } else if ( error ) {
    console.log( "The photo picker errored. Check ImagePicker.launchCamera func" )
    console.log( error )
  }
} )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: Rotate image in imageview by an angle
As of API 11, you can set the absolute rotation of an ImageView programmatically by using the imageView.setRotation(angleInDegrees); method. By absolute, I mean ......
Read more >
How to Rotate Photos on Android Phone or Tablet - Techbout
A single tap on the Rotate icon rotates the Photo by 90 degrees and you can keep tapping to Rotate more, until the...
Read more >
How to Rotate an Image to a Certain Angle in Android?
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for...
Read more >
How To Fix The Camera Intent Rotated Image In Android
Scale down the image if it was bigger than 1024×1024. · Rotate the image to the right orientation only if it was rotated...
Read more >
5 Best Free Apps to Rotate Images in 2022 [iOS & Android]
PhotoDirector has an easy-to-find, and simple-to-use rotate tool. The image will rotate 90 degrees with each tap for quick and easy rotation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found