简体   繁体   English

我的ImageView不刷新

[英]My ImageView doesn't refresh

I am trying to make an application that takes a picture and it display it on ImageView. 我正在尝试制作一个需要拍照的应用程序,并将其显示在ImageView上。

I succeded to make this but when I try to make a new picture the image from ImagaView is not refreshed. 我成功做到了,但是当我尝试制作新图片时,来自ImagaView的图像没有刷新。

For example: I push a button, an Intent to the Camera is created. 例如:我按一个按钮,就创建了一个相机意图。 I take picture 'A' which is saved on a file on the SD card at path 'fileUri' . 我拍摄图片“ A” ,该图片保存在SD卡上文件“ fileUri”的路径中。 Back in my activity mImageView1 shows the picture 'A' . 回到我的活动mImageView1显示图片'A' Nice.It works. 很好。

I try to take a new picture 'B' , I call the Intent the picture is saved at same adress.The picture is corectly saved, but when I return in my activity mImageView1 shows the old picture 'A' . 我尝试拍摄一张新图片'B' ,我称Intent图片保存在相同的地址。图片被严格保存,但是当我返回活动时mImageView1显示旧图片'A' Here is the code that changes the image of the ImageView: 这是更改ImageView图像的代码:

@Override
public void onPause(){
    super.onPause();
    ((BitmapDrawable) mImageView1.getDrawable()).setCallback(null);
}

@Override
public void onResume(){
    super.onResume();
    try{
        if(bImageSaved)
        {
            mImageView1.setImageURI(fileUri);
            mImageView1.postInvalidate();

        }
    }
    catch(Exception e)
    {
        e.printStackTrace();
         Log.e("Image2Notes",  e.getMessage(), e);
    }

I tried different things to refresh the ImageView: mImageView1.postInvalidate(); 我尝试了其他方法来刷新ImageView: mImageView1.postInvalidate(); mImageView1.draw(...); without succes. 没有成功。

If you have a hint I will be greatefull. 如果您有任何提示,我将不胜感激。 Thank you, 谢谢,

Start your camera activity for result using startActivityForResilt(). 使用startActivityForResilt()启动相机活动以获得结果。 And then override function onActivityResult (). 然后重写函数onActivityResult()。 So that when your camera activity finishes onActivityResult () function will get called. 这样,当您的相机活动完成时,就会调用onActivityResult()函数。 There in that function you can change the image other than changing it in onResume (). 除了在onResume()中更改图像外,您还可以在该函数中更改图像。 Check the activity result status in onActivityResult (). 在onActivityResult()中检查活动结果状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM