当源改变(已经使用无效)ImageView的不改变形象 [英] ImageView not changing image when source is changed (already using invalidate)

查看:196
本文介绍了当源改变(已经使用无效)ImageView的不改变形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML格式的一套图像的ImageView的。然而,当我试图改变图像的ImageView永远不会显示第二个图像。相反,它会显示一个空白屏幕。我曾尝试code带和不带无效()并没有改变。

  ImageView的形象;
字符串imgPath = Environment.getExternalStorageDirectory()+/音乐/伊凡塞斯 - 唱片 - 1998-2011(320 kbps的)/专辑/ 2000原产地(限量版)(320 kbps的)/扫描覆盖/ 06.jpg@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    图像=(ImageView的)findViewById(R.id.imageView1);    image.setImageBitmap(BitmapFactory.de codeFILE(imgPath));
    如果(!新文件(imgPath).exists())
        Log.i(AAA,文件犯规存在);
    //从图库中选择图片
    //意图photoPickerIntent =新意图(Intent.ACTION_PICK);
    //photoPickerIntent.setType(\"image/*);
    // startActivityForResult(photoPickerIntent,SELECT_PHOTO);
    Log.i(AAA,DONE IMG路径:+ imgPath);
}


解决方案

我觉得像过大。

在某些设备上,而不是 java.lang.OutofMemoryError 被抛出,一个空的位图被返回。

尝试用更小的图像运行您code。如果这样的作品,你一定要学会如何显示位图在适当的Andr​​oid版

(那么你要么办法)

I have an imageView with a set image in xml. However when I try to change the image the ImageView never displays the second image. Instead it displays a blank screen. I have tried the code with and without invalidate() and there is no change.

ImageView image;
String imgPath=Environment.getExternalStorageDirectory()+"/Music/Evanescence - Discography - 1998-2011 (320 kbps)/Album's/2000 Origin (Limited Edition) (320 kbps)/Scans covers/06.jpg";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image=(ImageView)findViewById(R.id.imageView1);

    image.setImageBitmap(BitmapFactory.decodeFile(imgPath));
    if(!new File(imgPath).exists())
        Log.i("aaa","File doesnt exist");
    //select image from gallery
    //Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    //photoPickerIntent.setType("image/*");
    //startActivityForResult(photoPickerIntent, SELECT_PHOTO); 
    Log.i("aaa","DONE. img path: "+imgPath);
}

解决方案

I think the image is too large.

On some devices, instead of java.lang.OutofMemoryError being thrown, a null bitmap is returned.

Try running your code with a smaller image. If that works, you have to learn how to display bitmaps properly in Android.

(Well either way you have to)

这篇关于当源改变(已经使用无效)ImageView的不改变形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆