2

I am using CameraIntent in my Application but the photo in the app got different resolution from the photo that is saved on the SDCard.

I am using the following code:

            Intent mCameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            mCameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
            startActivityForResult(mCameraIntent, mCameraRequest);


        protected void onActivityResult(int requestCode, int resultCode, Intent data)
        {
                if(requestCode == mCameraRequest)
                {
                    Bitmap photo = (Bitmap)data.getExtras().get("data");

                    int width = photo.getWidth();
                    int height = photo.getHeight();

                }
        }

The value of width is 320 and the value of height is 200, and on the SDCard the resolution of the photo is 2592x1552. I need the exact Width and Height in order to resize the photo for the desired resolution. What I am doing wrong? Are the getWidth() and getHeight() returning wrong values or?

Naskov
  • 4,121
  • 5
  • 38
  • 62
  • 1
    See this: http://stackoverflow.com/questions/6341329/built-in-camera-using-the-extra-mediastore-extra-output-stores-pictures-twice – sdabet Dec 19 '12 at 15:19

2 Answers2

4

The Bitmap that you receive in onActivityResult is a thumbnail.

If you want to have access to the actual file, you should provide the URI where you want the image to be saved with the EXTRA_OUTPUT intent extra:

Intent mCameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, outputUri);
mCameraIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
startActivityForResult(mCameraIntent, mCameraRequest);
sdabet
  • 18,360
  • 11
  • 89
  • 158
3

From the javadoc of android.provider.MediaStore.ACTION_IMAGE_CAPTURE

/** The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If
* the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object    in
* the extra field. This is useful for applications that only need a small image. If the
* EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of
* EXTRA_OUTPUT.
**/

As metionned in javadoc: you receive a small image. So I would suggest to use the EXTRA_OUTPUT and getting the size from the Bitmap stored on the sdcard. (see BitmapFactory.Options to get only the size of the image)

ben75
  • 29,217
  • 10
  • 88
  • 134