OnActivityResult不使用Picasso更新ImageView

时间:2015-11-17 08:14:19

标签: android imageview picasso onactivityresult

使用以下代码在ImageView

中查看捕获的图像
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(this.requestCode == requestCode && resultCode == RESULT_OK) {  
            File imageFile = new File(Environment.getExternalStorageDirectory() + "/img.jpeg");             
            Picasso.with(MainActivity.this).load(imageFile).into(imageView);
        }
    }

问题: 如何在ImageView中刷新onActivityResult(...),因为您可以看到我正在使用上面的代码但总是预览旧图像,而我在存储中获取新图像

2 个答案:

答案 0 :(得分:4)

您可以为这些代码替换代码: -

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(this.requestCode == requestCode && resultCode == RESULT_OK) {  
        File imageFile = new   File(Environment.getExternalStorageDirectory() + "/img.jpeg");             
        Picasso.with(MainActivity.this)
        .load(imageFile)
        .memoryPolicy(MemoryPolicy.NO_CACHE)
        .networkPolicy(NetworkPolicy.NO_CACHE)
        .error(R.drawable.ic_lanucher)
        .noFade()
        .into(imageView)

    }
}

答案 1 :(得分:0)

如果要加载捕获的图像,则需要从数据中获取位图,即Intent对象。



if (responseCode == RESULT_OK && data != null) {
			Bitmap bitmap = (Bitmap) data.getExtras().get("data");
			if (bitmap != null) {
				
			// Here you will get bitmap , set bitmap in imageview
			}
		}