每当我使用camera
裁剪图像时,出现错误Unable to load image
。但在gallery
的情况下,它运行良好。在android中裁剪图像
Uri uriPath = StoreAndFetchImageFromFile.getInstance(ParentDetails.this).getImageUri(partFilename);
selectedimagepath = getPath(uriPath);
Bitmap myBitmap = BitmapFactory.decodeFile(selectedimagepath);
parentimage.setImageBitmap(myBitmap);
performCropCamera(uriPath);
和方法imagecrop
是:
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();
}
}
而且OnActivity
结果进行图像裁切是:
if (requestCode == PIC_CROP) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");
parentimage.setImageBitmap(thePic);
}
请注意,裁剪功能对于Android不是强制性的,有些设备可能没有'com.android.camera.action.CROP'。所以使用外部裁剪功能是个不错的主意。我最好找一个作物的图书馆,并使用它。 –
好的。 Thnx但为什么会发生这种情况,在相机的情况下? – Vinay
[未发现可处理Intent com.android.camera.action.CROP的活动]的可能重复(https://stackoverflow.com/questions/41890891/no-activity-found-to-handle-intent-com-android- camera-action-crop) – W4R10CK