我試圖從Android攝像頭捕獲圖像/從圖庫中選取圖像,然後在對其執行其他操作之前對其進行裁剪。我無法取回裁剪圖像的URI。任何關於如何獲取圖像的URI一旦被裁剪的幫助將非常感謝!Android從意圖獲取裁剪圖像的URI
下面的代碼涉及到我的onActivityResult和我的功能行selectedImageUri = data.getData()
,其中data.getData()
返回空後已經做了農作物進行作物
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_FILE || requestCode == REQUEST_IMAGE_CAPTURE) {
if(!IS_CAMERA_USED) {
selectedImageUri = data.getData();
}
performCrop();
}
else if(requestCode == CROP_IMAGE){
selectedImageUri = data.getData();
onSelectedImageResult();
}
}
}
public void performCrop() {
// take care of exceptions
Display display = getWindowManager().getDefaultDisplay();
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(selectedImageUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate aspect of desired crop
cropIntent.putExtra("aspectY", 1);
if(IS_PROFILE_PICTURE) {
cropIntent.putExtra("aspectX", 1);
}
else {
cropIntent.putExtra("aspectX", 2);
}
// indicate output X and Y
cropIntent.putExtra("outputX", display.getWidth());
cropIntent.putExtra("outputY", display.getHeight());
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_IMAGE);
}
// 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();
}
}
的問題。如何找回裁剪圖像的URI?我不想得到data.getExtras.getParcelable("data")
,因爲它會返回縮略圖並且會破壞圖像分辨率。
在此先感謝!
[ Android沒有'CROP''Intent'](https://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html)。有很多[可用於Android的圖像裁剪庫](https://android-arsenal.com/tag/45)。請使用一個。 – CommonsWare