2012-12-10 24 views
0

我正在添加覆盖图来映射一些.png文件。它工作正常,但有时会引发位图大小超过虚拟机预算错误。当将图像添加到列表视图时发生同样的问题时,我通过应用SoftReference来解决它。但我不知道如何将它应用于在mapview中添加叠加层。请任何想法。由于位图大小超过了mapview addoverlay

这样

public ItemizedOverlayMarker(Drawable defaultMarker, Context context) { 
    super(boundCenterBottom(defaultMarker)); 
    mContext = context; 
} 

@Override 
protected OverlayItem createItem(int i) { 
    return mOverlays.get(i); 
} 

@Override 
public int size() { 
    return mOverlays.size(); 
} 
public void addOverlay(OverlayItem overlay) { 
    mOverlays.add(overlay); 
    populate(); 
} 

调用ItamizerOverlay这样添加叠加:

final List<Overlay> mapOverlaysResult = mapView.getOverlays(); 
Drawable drawableResult = getResources().getDrawable(R.drawable.pin_pink); 
final ItemizedOverlayMarker itemizedoverlayResult = new ItemizedOverlayMarker(drawableResult, this); 

for (int i = 0; i < Constants.listOfPlaces.size(); i++) { 

    GeoPoint geoPoint = new GeoPoint((int)(Double.parseDouble(latitude) * 1E6), (int)(Double.parseDouble(longitude) * 1E6)); 
    OverlayItem overlayitem = new OverlayItem(geoPoint, name, vicinity); 
    itemizedoverlayResult.addOverlay(overlayitem); 
       } 
+0

有没有outOfMemory错误? –

+0

yesof outofMemoryError:位图大小超过虚拟机预算 – Sri

+0

您可以通过代码了解如何从webURL加载图像并将其添加到覆盖图上 –

回答

-1

首先将图像文件对象

,并通过下面函数将返回位图..

private Bitmap decodeFile(File f) 
    { 
     try 
     { 
      //decode image size 
      BitmapFactory.Options o = new BitmapFactory.Options(); 
      o.inJustDecodeBounds = true; 
      BitmapFactory.decodeStream(new FileInputStream(f),null,o); 

      //Find the correct scale value. It should be the power of 2. 
      final int REQUIRED_SIZE=70; 
      int width_tmp=o.outWidth, height_tmp=o.outHeight; 
      int scale=1; 
      while(true) 
      { 
       if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE) 
        break; 
       width_tmp/=2; 
       height_tmp/=2; 
       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; 
    } 
+0

为什么要投票?这有什么问题? –

相关问题