Every time I crop an image using a camera
I got an error Unable to load image
. But in the case of the gallery
, it worked fine.
Uri uriPath = StoreAndFetchImageFromFile.getInstance(ParentDetails.this).getImageUri(partFilename);
selectedimagepath = getPath(uriPath);
Bitmap myBitmap = BitmapFactory.decodeFile(selectedimagepath);
parentimage.setImageBitmap(myBitmap);
performCropCamera(uriPath);
And method for imagecrop
is:
private void performCropCamera(Uri picUri) {
// take care of exceptions
try {
// call the standard crop action intent (the user device may not
// support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
int asp = (int) (DeviceDimensions.getScreenWidth() - 80)/187;
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", asp);
cropIntent.putExtra("aspectY", 3);
// indicate output X and Y
cropIntent.putExtra("outputX", DeviceDimensions.getScreenWidth() - 80);
cropIntent.putExtra("outputY", 187*3);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
Toast toast = Toast
.makeText(this, "This device doesn't support the crop action!", Toast.LENGTH_SHORT);
toast.show();
}
}
And the OnActivity
result for image crop is:
if (requestCode == PIC_CROP) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
parentimage.setImageBitmap(thePic);
}