我有以下代码供用户裁剪图像。当我将尺寸设置为256以上时,它不起作用。我的直觉是“cropIntent.putExtra(”return-data“,true);”导致错误。如何将uri传递给cropIIntent并从onActivityResults中检索出来?换句话说,在裁剪和检索后保存图像。Android作物图像大小
private void performCrop() {
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(mImageCaptureUri, "image/*");
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 4);
cropIntent.putExtra("aspectY", 3);
//indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
//retrieve data on return
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
} //respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
//display an error message
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PIC_CROP) {
try {
final TextView imgTv = (TextView) findViewById(R.id.imageInfo);
Bundle extras = data.getExtras();
thumbnail = extras.getParcelable("data");
ImageView image = (ImageView) findViewById(R.id.pestImage);
image.setImageBitmap(thumbnail);
File f = new File(mImageCaptureUri.getPath());
if (f.exists()) {
f.delete();
}
}
}//end onactivity results
我不需要URI传递到cropIntent?当我得到filePath时,我该如何转换为位图? – user903772 2013-04-04 10:01:34
你能提供更多的细节吗? – user903772 2013-04-04 10:49:29
我认为你不需要传递一个Uri,看看resultCode是否成功,我添加了从文件路径加载位图的代码。 – 2013-04-04 12:23:27