I make a custom camera on android and faced with the orientation problem. Activity with surfaceview is portrait orientation, because of this not work onConfigurationChanged listener, but I whant it. I want to save picture from camera always in normal orientation,but the images are saved with different orientations depending on how the orientation of the photo was taken.
code:
public void onClickPicture(View view) {
camera.takePicture(null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
FileOutputStream fos = new FileOutputStream(photoFile);
fos.write(data);
fos.close();
Bitmap bm = BitmapFactory.decodeByteArray(data,0,data.length);
ExifInterface ei;
ei = new ExifInterface(photoFile.getAbsolutePath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_NORMAL:
//ALAWAYS THIS CASE
break;
case ExifInterface.ORIENTATION_ROTATE_90:
bm = rotateImage(bm, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
bm = rotateImage(bm, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
bm = rotateImage(bm, 270);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
});
}