tags:

views:

1117

answers:

3

Hi,

Posted this on the android dev forum, wondering if anyone here has seen this.

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 sdk level 5?

Thanks

A: 

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).

Christopher
Oh wow that doesn't sound pleasant - should I instead just start using the 2.0 API (looks like level 6), and if I see API < 6, then use that parameters call instead? I don't know if I could go the other direction?Thanks
Mark
A: 

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.

chihchung
A: 

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:

http://android.git.kernel.org/?p=platform/packages/apps/Camera.git

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.

Corey Trager