Question

I'm using this camera code to ask the camera to rotate the captured image data:

Camera.Parameters params = camera.getParameters();
params.set("rotation", 90);
camera.setParameters(params);

this seems to work on all phones, except the Droid. Has anyone else seen this? The image data is always landscape, however, the native camera app on the Droid produces portrait images ok.

I wonder if the Droid will only respect the new Camera.Parameters.setRotation() method, but this seems to only be available in API level 5?

Was it helpful?

Solution

The rotation may just be stored in the jpeg exif header as explained in the setRotation document. On Droid that is actually the case. You can use jpeg header reading tools like jhead to verify this. You can also use the ExifInterface API to read the orientation tag in your program.

OTHER TIPS

setRotation also didn't seem to work for me on Nexus One, but I did get image rotation to work by following the example of the android Camera app itself.
The source code is available here: https://android.googlesource.com/platform/packages/apps/Camera

Start with the Camera.java, but you'll also be looking at ImageManager.java, Util.java, and other files.

The basic idea is, you listen for orientation changes and capture what the orientation is at the time you snapped the picture. Then, when you get the picture bytes in the callback, you manipulate the bitmap, doing a rotation on the bitmap. Then convert the rotated bitmap back to jpeg. When you are done, you'll have had to copy a shocking amount of code from the camera app just for this rotation.

The Droid runs Android 2.0 (well, now 2.0.1) which are API levels 5 and 6, respectively.

So it's quite possible that the Droid only respects the (more sensible) 2.0+ API for rotation.

However, I guess your concern is compatibility across a range of device types and OS versions, so I imagine you would have to invoke the 2.0+ API via reflection after detecting the OS version (using android.os.Build.VERSION_CODES).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top