I have written an Android activity that captures a photo programatically. I want to save the image as a JPEG with the correct EXIF orientation data (just like the native Android Camera app does automatically).
Here is the method for actually taking the photo (I removed the try/catch blocks):
private void takePhoto() {
camera = Camera.open();
SurfaceTexture dummySurfaceTexture = new SurfaceTexture(0);
camera.setPreviewTexture(dummySurfaceTexture);
camera.startPreview();
camera.takePicture(null, null, jpgCallback);
}
...and the callback:
private Camera.PictureCallback jpgCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
releaseCamera();
savePhoto(data);
};
The photo is taken properly, but my problem is that the EXIF data shows that the orientation is set to "Image Orientation: Top, Left-Hand" regardless of the orientation of the device, so that when I upload the photo it appears upside down or rotated.
Do I really need to capture the device orientation manually (roll, pitch, azimuth) and write the EXIF orientation myself? How does the Camera app automatically write this data correctly? Does anyone know of a way to set this attribute correctly?
EDIT: I can't use the screen orientation as the Activity is locked to portrait mode.