Crop不工作后的ImageView setImageBitmap

时间:2016-05-05 12:12:45

标签: android bitmap imageview

这是我的代码:

File cropImage = new File(Environment.getExternalStorageDirectory(), "o_crop_image.jpg");
try {
    if (cropImage.exists()) {
        cropImage.delete();
    }
    cropImage.createNewFile();
} catch (IOException e) {
    e.printStackTrace();
}
cropUri = Uri.fromFile(cropImage);

Intent i = new Intent("com.android.camera.action.CROP");
i.setDataAndType(imageUri, "image/*");     //imageUri is the original image
i.putExtra("scale", true);
i.putExtra(MediaStore.EXTRA_OUTPUT, cropUri);
startActivityForResult(i, CROP_PHOTO);

onActivityResult

case CROP_PHOTO:
if (resultCode == RESULT_OK) {  
     Bitmap bitmap = BitmapFactory.decodeFile(cropImage.getAbsoluteFile());
     photo.setImageBitmap(bitmap);  //photo is an ImageView
}
break;

代码photo.setImageBitmap(bitmap)应该有效,但ImageView没有显示任何图片。我得到的位图是可以的,我可以在SD中找到。

甚至其他位图也无法在ImageView中设置,但方法setImageResource也可以。我有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这是我的错误,我将i.putExtra("scale", true)更改为i.putExtra("scale", "true")后发现setImageBitmap工作了。我不知道为什么,但这确实解决了我的问题。