Stephen Burns
Stephen Burns

Reputation: 172

Why am I getting low res photos when taking pictures using an app in android?

When I'm taking pictures using the camera functionality in my app, it's returning a low res image even though the camera preview is a good resolution. My code for calling the code is:

final Button takePicButton = (Button) findViewById(R.id.takePicButton);
    takePicButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, REQUEST_CAMERA);
        }
    });

My code for the activity result is:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CAMERA && resultCode == Activity.RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);

Upvotes: 2

Views: 1790

Answers (3)

AndroidGeek
AndroidGeek

Reputation: 409

Uri selectedImage = data.getData();
Bitmap picTaken = getBitmapFromUri(selectedImage);

use this function to get image from URI

private Bitmap getBitmapFromUri(Uri uri) throws IOException {
    ParcelFileDescriptor parcelFileDescriptor =
            getActivity().getContentResolver().openFileDescriptor(uri, "r");
    FileDescriptor fileDescriptor;
    if (parcelFileDescriptor != null) {
        fileDescriptor = parcelFileDescriptor.getFileDescriptor();
        Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
        parcelFileDescriptor.close();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        image.compress(Bitmap.CompressFormat.PNG, 50, out);
        return BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
    }
    return null;
}

Upvotes: 0

sansa
sansa

Reputation: 434

Starting the the camera with ACTION_IMAGE_CAPTURE , will always use the camera settings already saved on the camera, for example if the camera is setted out on low resolution (the user's config, use of another camera app ..) , even if you specify the uri you will get always low resolution.

So you have two options:

  • Build you own camera activity and set its setting to high resolution
  • Ask the user to set the camera resolution manually before starting the capture

Upvotes: 0

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

Because (Bitmap) data.getExtras().get("data"); will return a thumbnail (low resolution) pic

Solution : you need to use the URI mechanism (path to image file) and query the MediaProvider to fetch the full resolution image

Save the Full-size Photo

Upvotes: 2

Related Questions