我在onMapReady里面有这段代码,它设置了经/纬度,并开始了准备覆盖图像的异步任务。
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
moveToCurrentLocation(mGoogleMap,new LatLng(49.26874005, -123.19854477));
newarkBounds= new LatLngBounds(
new LatLng(49.26874005, -123.19854477), // South west corner
new LatLng(49.27462099, -123.19069126)); // North east corner*//*
// Adds a ground overlay with 50% transparency.
new BitmapWorkerTask().execute();
}
这是准备图像并将其设置为Google地图的代码。
class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> {
private int data = 0;
public BitmapWorkerTask() {
// Use a WeakReference to ensure the ImageView can be garbage collected
}
// Decode image in background.
@Override
protected Bitmap doInBackground(Integer... params) {
imageDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.vfmf_overlay);
return null;
}
// Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) {
mGoogleMap.addGroundOverlay(new GroundOverlayOptions()
.image(imageDescriptor)
.positionFromBounds(newarkBounds));
}
}
我当前的图像为63KB,当我放大到最大时,我可以看到图像文件(.png),非常清晰,但是当缩小时,它看起来像一张碎纸片。它不见了。但是,当我使用332 KB的同一图像时,应用程序崩溃并出现内存不足的情况。使用相同的代码。知道为什么会这样吗?