public static Bitmap getImageFromAssetsFile(Resources res,String fileName)  
  {  
      Bitmap image = null;  
      AssetManager am = res.getAssets();  
      InputStream is = null;  
      try  
      {  
       is=am.open(fileName);
          image = BitmapFactory.decodeStream(is);  
      }  
      catch (IOException e)  
      {  
          e.printStackTrace();  
      } finally{
       if(is!=null){
       try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}  
       }
      } 
      return image;  
  }  这是我加载图片的代码。
我一次加载了几十张图片,就报01-04 01:50:12.964: ERROR/AndroidRuntime(325): java.lang.OutOfMemoryError: bitmap size exceeds VM budget网上搜了很多方法都得不到解决。求解决办法或思路。
求优化办法或思路。

解决方案 »

  1.   

    图片资源用完回收掉吧  bmp.recycle()
      

  2.   

    这个问题是所有做android app都会碰到而且必须学会解决的问题 网上很多 自己找找吧 oom
      

  3.   

    资源管理,你只加载不清除,再多的内存也被你用光啊,你用到的时候加载进来,用完就recycle()掉。
      

  4.   

    2L说的正确的呀。。LZ不明白?
      

  5.   

    这个问题都不知道说了多少遍了,其实还是需要具体情况具体分析。
    LZ Google一下java.lang.OutOfMemoryError,会收获很多,还是要自己实践的。
      

  6.   


    private void dispalyNextImage() {
    // 如果发生数组越界
    if (currentImg >= images.length) {
    currentImg = 0;
    }
    //备注1
    // 找到下一个图片文件
    while (!images[currentImg].endsWith(".png")
    && !images[currentImg].endsWith(".jpg")
    && !images[currentImg].endsWith(".gif")) {
    currentImg++;
    // 如果已发生数组越界
    if (currentImg >= images.length) {
    currentImg = 0;
    }
    } InputStream assetFile = null;
    try {
    // 打开指定资源对应的输入流
    assetFile = assets.open(images[currentImg++]);
    } catch (IOException e) {
    e.printStackTrace();
    }

    BitmapDrawable bitmapDrawable = (BitmapDrawable) image.getDrawable();
    //备注2
    // 如果图片还未回收,先强制回收该图片
    if (bitmapDrawable != null && !bitmapDrawable.getBitmap().isRecycled()){
    bitmapDrawable.getBitmap().recycle();
    }
    // 改变ImageView显示的图片
    image.setImageBitmap(BitmapFactory.decodeStream(assetFile));
    }
    }提供代码吧,更直接一些!!