Reputation: 172
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
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
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:
Upvotes: 0
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
Upvotes: 2