Reputation: 1783
I'm trying to show to the user image from camera with right side up - no regard to how he holds the phone.
My code is simple:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("return-data", true);
startActivityForResult(cameraIntent, CAMERA_RESULT);
Then I attach returned image to ImageView in onActivityResult.
I know how to rotate the image, but how can I know how user hold the camera when he took a picture?
Upvotes: 0
Views: 94
Reputation: 721
I'm almost sure you can't do that using the "return-data" extra. You'll have to pass the filename of where you wan't the picture be created, and then use the Exif of the file to check the orientation.
String FOLDER = "YOUR_FOLDER";
String FILENAME = "YOUR_FILENAME";
int TAKE_PHOTO_REQUEST_CODE = 0;
File photoFile;
void TakePhoto()
{
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photoFile = new File(FOLDER , FILENAME );
Uri pictureFileUri = Uri.fromFile(photoFile);
takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, pictureFileUri);
startActivityForResult(takePictureIntent, TAKE_PHOTO_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case TAKE_PHOTO_REQUEST_CODE:
if(resultCode == RESULT_OK)
{
int orientation = 0;
try
{
ExifInterface exif = new ExifInterface(path);
int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
switch (exifOrientation)
{
case ExifInterface.ORIENTATION_NORMAL:
orientation = 0;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
orientation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
orientation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
orientation = -90;
break;
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Here you can rotate the bitmap knowing the orientation of the camera when the photo was taken
}
}
Upvotes: 1