1

I would like to launch the native Android camera and save the image at a specified location. The problem is after I click the capture photo, the preview comes up with the options to Save/Discard. After I click save, the native camera rotates in landscape and the image I captured is not displayed.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.setPackage(defaultCamera);
            File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
            startActivityForResult(intent, 1); 
BaCaRoZzo
  • 7,222
  • 6
  • 51
  • 77

2 Answers2

0

It is because the activity is recreated therefore data is not there anymore. You cannot control whether that will happen or not. Do you capture the picture onActivityResult? If so, you could try saving the path in a retained fragment.

Alex
  • 108
  • 1
  • 11
0

Some devices rotate the image before saving it.

Check the photo's exif data and looking particularly for

ExifInterface exifInterf = new ExifInterface(SourceFileName);
int exifOrientation = exifInterf.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

switch (exifOrientation ) {
  case ExifInterface.ORIENTATION_ROTATE_270:
    rotate = 270;
    break;
  case ExifInterface.ORIENTATION_ROTATE_180:
    rotate = 180;
    break;
  case ExifInterface.ORIENTATION_ROTATE_90:
    rotate = 90;
    break;
}

Matrix matrix = new Matrix();
matrix.postRotate(rotate);
bitmap = Bitmap.createBitmap(bitmap , 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
jlopez
  • 6,287
  • 2
  • 51
  • 90