Camera: Wrong orientation with Android


#1

Hey guys …
I am encountering some problem with Cordova Camera plugin and Android.

When taking picture in Android (e.g. in portrait mode) the image is rotated by -90° …
With the same code in iOS all works fine and have the correct orientation.

Someone has already had experience on this probem?

This is my code:

var cameraOptions = {
	quality: 75,
	sourceType: Camera.PictureSourceType.CAMERA,
	destinationType: Camera.DestinationType.FILE_URI,
	targetWidth: 600,
	encodingType: Camera.EncodingType.PNG,
	correctOrientation: true
};

$cordovaCamera.getPicture(cameraOptions).then(function(fileURI)
{
    ....
}

My project use:
Cordova 3.5.0-0.2.7
Cordova Camera plugin 0.3.1

I’ve made some search and I have found this post … but doesn’t solve the problem.

Cheers


#2

Oh another thing …
I’ve tried in this days with a Nexus 5 and the latest version of Android:

The orientation is correct!!
But with Samsung Galaxy S4 and the latest version le orientation is wrong.

Anyone have experience with this problem with Android??


#3

Got the same issue with Cordova. I think this issue is in S4 only.


#4

The root cause of this issue is the following piece of code:

                        try {
                        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                        this.orientationCorrected = true;
                    } catch (OutOfMemoryError oom) {
                        this.orientationCorrected = false;
                    }

Basically this means that if images are not rotated correctly, you have to lower the width and height parameters so that the whole picture fits in memory. My local tests show that 8 mp resolution fails on S4, while 3 mp works fine.


#5

Is there a fix for this, Users for my app are reporting this. But only users using a samsung variant. Any idea what the problem might be and we are yet to test.


#6

I’ve been searching all over the web for this issue. It goes pretty deep it seems.
I see people talking about Android stripping EXIF info so the webview doesn’t know the pic is rotated, most issues should be resolved according to blogs, issuetrackers and stack overflow questions.

However, I am still experiencing this issue as well!
I tried playing around with the settings (bigger / smaller target sizes, enable / disable the fixOrientation, save to album option, etc) but it ALWAYS remains rotated -90 when the picture is taking portrait mode.

I even tried to read the EXIF data myself using a plugin, but it returns “undefined”. Probably because android strips it.

So i’m kind of running out of resources here!


#7

I had this issue on my Samsung Galaxy S5 (which allows up to 16MB images) and had to use
encodingType: Camera.EncodingType.JPEG instead of PNG
along with the targetWidth: 720 in order avoid the wrong orientation issue.


#8

Hi

Did you get any final solution with this.Even i am stuck on the same thing and seems to be out of options…

Thansk
Siddhant


#9

Setting Camera.EncodingType.JPEG instead of Camera.EncodingType.PNG has helped me. Running on Sony Xperia Z1.


#10

Got the same issue on Galaxy S3. It works correctly only with 800 x 600 dimensions. @thlassche, how do you think, is there any possibility to fix that?


#11

I fixed it by doing version checks on different devices and lower the resolution accordingly, until the picture fits in the memory.


#12

@thlassche, thanks. I’v just updated to the latest dev version of the cordova’s camera plugin (cordova plugin add https://github.com/apache/cordova-plugin-camera) and found out that the issue is no more for me. Seems like correctOrientation: true works as expected now.

Can you please confirm this regarding to your devices?

My plugin version is 0.3.5-dev


#13

Confirmed. Just checked and it’s working


#14

I have reinstalled the plugin, but got 0.3.4.

Release Notes:

0.3.4 (Dec 02, 2014)

  • CB-7977 Mention deviceready in plugin docs
  • CB-7979 Each plugin doc should have a ## Installation section
  • Fix memory leak of image data in imagePickerControllerReturnImageResult
  • Pass uri to crop instead of pulling the low resolution image out of the intent return (close #43)
  • Add orientation support for PNG to Android (closes #45)
  • CB-7700 cordova-plugin-camera documentation translation: cordova-plugin-camera

Are you sure it’s 0.3.5-dev?


#15

@bwasnie1, yep I’m pretty sure with it.

How do you install the plugin? Try to copy and paste this code:

cordova plugin rm org.apache.cordova.camera
cordova plugin add https://github.com/apache/cordova-plugin-camera

Notice that I use https address of the repository instead of it’s alias.


#16

You are right, sry :slight_smile:


#17

@bwasnie1, no problem!


#18

I did this, and I’m on 0.3.5 of the camera plugin, still no joy. tried this on Note 4 and Xperia Z Ultra, doesnt work. Strange enough, works fine on my nexus 5. Anyone any suggestions please?


#19

I have noticed that its very samsung specific this issue I had an HTC never saw it but on samsung it happens


#20

U can download app library for developer
https://play.google.com/store/apps/details?id=com.libraries.developers

i see it has sourcecode vary lib ulits for android and it reslove problem of U `

I try to it , see it correct with all mobile devices