2012-05-23 98 views
0

我得到着名的内存不足错误。但是我已经尝试了很多关于这个问题的建议解决方案,但没有任何运气。我明白,为了防止位图超过内存,您将绘制一个静态变量(Android文档)。但是,这是不适用于我的应用程序,因为我有很多标记,你可以看到..Android位图内存不足错误(mapviewBalloons)

有没有人有一个解决方案的建议?

for(Poi p : poiarray){ 

       WeakReference<Bitmap> bitmap = new WeakReference<Bitmap>(p.get_poiIcon()); 
       if(bitmap!=null){ 

        Drawable marker = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap.get(), 60, 60, true)); 
       annotationOverLays.add(new CustomAnnotation(marker,p,this,mapView));  
       //mapView.getOverlays().add(new CustomAnnotation(marker,p,this,mapView)); 
       } 
      } 
      mapView.getOverlays().addAll(annotationOverLays); 

错误:

05-23 13:08:31.436: E/dalvikvm-heap(22310): 20736-byte external allocation too large for this process. 
05-23 13:08:31.436: E/dalvikvm(22310): Out of memory: Heap Size=23111KB, Allocated=22474KB, Bitmap Size=1505KB 
05-23 13:08:31.436: E/GraphicsJNI(22310): VM won't let us allocate 20736 bytes 

编辑:

我想我可能已经本地化的问题..我可以触发内存溢出的异常,如果我在几个注释的点击。我使用Here的mapViewBalloons,当我打开关闭2几次时,我的应用程序崩溃与例外。任何人有类似的问题?

回答

1

我有同样的问题,下面的代码为我工作:

public static Bitmap decodeFile(File f, boolean goodQuality){ 
     try { 
      //Decode image size 
      BitmapFactory.Options o = new BitmapFactory.Options(); 
      o.inJustDecodeBounds = true; 
      BitmapFactory.decodeStream(new FileInputStream(f),null,o); 

      //The new size we want to scale to 
      final int REQUIRED_SIZE=100; 

      //Find the correct scale value. It should be the power of 2. 
      int scale=1; 
      if(!goodQuality){ 
       while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=REQUIRED_SIZE) 
        scale*=2; 
      } 
      //Decode with inSampleSize 
      BitmapFactory.Options o2 = new BitmapFactory.Options(); 
      o2.inSampleSize=scale; 
      return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); 
     } catch (FileNotFoundException e) {} 
     return null; 
    }