每當我使用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