我正在使用一些.png文件添加叠加层来映射。它工作正常,但有时会抛出位图大小超过VM预算错误。当将图像添加到listview时出现同样的问题时,我通过应用SoftReference解决了它。但我不知道如何应用它来在mapview中添加叠加层。请任何想法。感谢
像这样添加叠加
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 :(得分:-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;
}