Android - Camera Intent Low Bitmap Quality
When taking a picture using the android camera Intent, I get a low-quality bitmap image. I was wondering if it is possible to make this image decent quality. I googled some informa
Solution 1:
Don't use bitmap
, use uri
instead.
ImageView imageView;
Uri image;
String mCameraFileName;
privatevoidcameraIntent() {
StrictMode.VmPolicy.Builderbuilder=newStrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Intentintent=newIntent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
Datedate=newDate();
DateFormatdf=newSimpleDateFormat("-mm-ss");
StringnewPicFile= df.format(date) + ".jpg";
StringoutPath="/sdcard/" + newPicFile;
FileoutFile=newFile(outPath);
mCameraFileName = outFile.toString();
Uriouturi= Uri.fromFile(outFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri);
startActivityForResult(intent, 2);
}
@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 2) {
if (data != null) {
image = data.getData();
imageView.setImageURI(image);
imageView.setVisibility(View.VISIBLE);
}
if (image == null && mCameraFileName != null) {
image = Uri.fromFile(newFile(mCameraFileName));
imageView.setImageURI(image);
imageView.setVisibility(View.VISIBLE);
}
Filefile=newFile(mCameraFileName);
if (!file.exists()) {
file.mkdir();
}
}
}
}
Solution 2:
in your cameraIntent you need to specify the uri when the camera activity will save the picture with the full resolution:
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
if you don't specify that you just receive a thumbnail in the onActivityResult. So you specify that and you read the image from the uri.
So in your onActivityResult you should do:
BitmapFactory.Optionsoptions=newBitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmapbitmap= BitmapFactory.decodeFile(capturedImageUri, options);
that's it.
Solution 3:
You have to save the image in the storage in order to get the full sized image. Check this: http://developer.android.com/training/camera/photobasics.html#TaskPath
Post a Comment for "Android - Camera Intent Low Bitmap Quality"