错误提示05-21 07:00:05.659: E/dalvikvm-heap(974): 64240-byte external allocation too large for this process.
05-21 07:00:05.688: E/GraphicsJNI(974): VM won't let us allocate 64240 bytes
05-21 07:00:05.688: D/skia(974): --- decoder->decode returned false图片加载到300张左右的时候就出现了上面的错误,用mat分析内存共2.4M各位给点意见呀

解决方案 »

  1.   

    这个demo中应该有你想要的:
    http://download.csdn.net/detail/fire_fire_fire/4317821
    看里面的onActivityResult方法,这里面做了内存溢出处理。
      

  2.   

    BitmapFactory.Options  并不能解决根本问题呀  
      

  3.   

    本帖最后由 yiyaaixuexi 于 2012-05-22 09:42:05 编辑
      

  4.   

    那你就做个集合缓存,将图片放到该集合中,取图片就从该集合中取,然后在一定的时候判断它的数量,如果达到了一定数量,如300张,就删除最前面的一百张或直接清空该集合,这样应该就不会溢出了
    Map<String, SoftReference<Drawable>> cache = new HashMap<String, SoftReference<Drawable>>();
      

  5.   

    你看看下面的,用了缓存的,只是没有做判断缓存大小或数量的处理
    调用:String strurl = "图片路径";
    CallbackImg iCallBack = new CallbackImg(imageView);//imageView为界面的控件
    Drawable drawable = asyncImageLoad.getDrawable(strurl, iCallBack);
    if (drawable != null) {
    imageView.setImageDrawable(drawable);
    }AsyncImageLoad :public class AsyncImageLoad {
    private Map<String, SoftReference<Drawable>> cache = new HashMap<String, SoftReference<Drawable>>(); public Drawable getDrawable(final String strurl, final ICallBack iCallBack) {
    if (cache.containsKey(strurl)) {
    SoftReference<Drawable> soft = cache.get(strurl);
    if (soft.get() != null) {
    return soft.get();
    }
    } final Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
    iCallBack.loadImage((Drawable) msg.obj);
    }
    }; new Thread() {
    @Override
    public void run() {
    Drawable drawable = loadForUrl(strurl);
    if (drawable != null) {
    cache.put(strurl, new SoftReference<Drawable>(drawable));
    Message msg = handler.obtainMessage(0, drawable);
    msg.obj = drawable;
    handler.sendMessage(msg);
    }
    }
    }.start(); return null;
    } protected Drawable loadForUrl(String strurl) {
    try {
    URL url = new URL(strurl);
    HttpURLConnection httpURLConnection = (HttpURLConnection) url
    .openConnection();
    httpURLConnection.setDoInput(true);
    httpURLConnection.connect();
    InputStream inputStream = httpURLConnection.getInputStream();
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
    Drawable drawable = new BitmapDrawable(bitmap);
    return drawable;
    } catch (Exception e) {
    return null;
    }
    } public interface ICallBack {
    void loadImage(Drawable drawable);
    }
    }CallbackImg public class CallbackImg implements ICallBack{
    private ImageView imageView;

    public CallbackImg(ImageView imageView){
    this.imageView=imageView;
    }

    @Override
    public void loadImage(Drawable drawable) {
    imageView.setImageDrawable(drawable);
    }
    }
      

  6.   

    你按下面这样做了不行?if(cache.size()>=300){
    cache.clear();
    }你是用什么去显示图片?ListView还是什么?有没有做它的优化?
      

  7.   

    这样写的  不行public void addImageCache(String imageUrl,Bitmap bmp){
    if(imageCache.size()>20){
    imageCache.clear();
    System.gc();
    }
    imageCache.put(imageUrl, new SoftReference<Bitmap>(bmp));
    }
      

  8.   

    如果你是用的listview,看看这篇文章对你有用吗:
    http://www.iteye.com/topic/1118828
      

  9.   

    应该是Lz本身的图片太大了吧,lz 的图片有多大先?
      

  10.   

    应该是Lz本身的图片太大了吧,lz 的图片有多大先?
      

  11.   

    --- decoder->decode returned false这个貌似解码出错了,估计里面有图片太大解码不支持出错了
      

  12.   

    她说加载到300张左右的时候出现问题,我估计有几种情况:1.刚好某一张图片过大,导致内存溢出,这样的情况应该使用BitmapFactory.Options压缩图片2.图片集合一直存在内存中,积压过多导致溢出,这样的情况应该定时清空图片集合,并使用图片软引用,让虚拟机能够及时回收内存。并且对展示图片的控件做优化(如listview)。