Android 无法分配dup blob fd
我的应用程序在地图上有大约1500个标记,这些标记通过集群显示,以避免应用程序过载。这些书签当前显示为BitmapDescriptorFactory.defaultMarker() 但是,当我修改每个点的代码以显示带有标记值的自定义位图时,只有少数设备存在此错误,其中包括LG K10 LTE和一些Motorolas。大多数电器工作正常 使用此函数时,在渲染完所有1500个标记之前,它会崩溃,并出现以下错误: “无法分配dup blob fd。” 在对这个错误的研究中,我认为这是一个内存溢出,我应该将这些标记存储在LRU缓存中,但我无法将其与集群结合使用 有没有人有过这样的想法或建议来解决这个问题 以下是位图渲染器代码段:Android 无法分配dup blob fd,android,google-maps,bitmap,marker,Android,Google Maps,Bitmap,Marker,我的应用程序在地图上有大约1500个标记,这些标记通过集群显示,以避免应用程序过载。这些书签当前显示为BitmapDescriptorFactory.defaultMarker() 但是,当我修改每个点的代码以显示带有标记值的自定义位图时,只有少数设备存在此错误,其中包括LG K10 LTE和一些Motorolas。大多数电器工作正常 使用此函数时,在渲染完所有1500个标记之前,它会崩溃,并出现以下错误: “无法分配dup blob fd。” 在对这个错误的研究中,我认为这是一个内存溢出,我应
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
OwnRendring(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.snippet(item.getSnippet());
markerOptions.title(item.getTitle());
markerOptions.anchor(0.33f, 1f);
markerOptions.infoWindowAnchor(0.33f,0f);
int cor = (item.getPublico() ? cfgCorPostoPublico : cfgCorPostoPrivado);
String preço = item.getTitle().substring(item.getTitle().length() - 5);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(createMarker(preço, cor)));
super.onBeforeClusterItemRendered(item, markerOptions);
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
return cfgCluster && cluster.getSize() >= cfgClusterMin;
}
}
@Override
public void onCameraIdle() {mClusterManager.cluster();}
private Bitmap createMarker(String text, int color) {
View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);
ImageView markerImage = markerLayout.findViewById(R.id.marker_image);
TextView markerRating = markerLayout.findViewById(R.id.marker_text);
markerImage.setImageResource(R.drawable.pin_shadow);
markerImage.clearColorFilter();
markerImage.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY );
markerRating.setText(text);
markerLayout.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight());
final Bitmap bitmap = Bitmap.createBitmap(
markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
markerLayout.draw(canvas);
return bitmap;
}
public类OwnRendring扩展了DefaultClusterRenderer{
OwnRendring(上下文上下文、Google地图、ClusterManager ClusterManager){
超级(上下文、地图、群集管理器);
}
在呈现BeforeClusterItem(MyItem项、MarkeOptions MarkeOptions)之前受保护的void{
markerOptions.snippet(item.getSnippet());
markerOptions.title(item.getTitle());
标记选项。锚(0.33f,1f);
标记选项。infoWindowAnchor(0.33f,0f);
int cor=(item.getPublico()?cfgCorPostoPublico:cfgCorPostoPrivado);
String preço=item.getTitle().substring(item.getTitle().length()-5);
图标(BitmapDescriptorFactory.fromBitmap(createMarker(preço,cor));
super.onBeforeClusterItemRendered(项目、标记选项);
}
受保护的布尔值shouldRenderAsCluster(群集){
返回cfgCluster&&cluster.getSize()>=cfgClusterMin;
}
}
@凌驾
public void onCameraIdle(){mClusterManager.cluster();}
专用位图createMarker(字符串文本,int颜色){
View markerLayout=GetLayoutFlater().充气(R.layout.custom_标记,空);
ImageView markerImage=markerLayout.findviewbyd(R.id.marker\u图像);
TextView markerRating=markerLayout.findviewbyd(R.id.marker\u text);
markerImage.setImageResource(R.drawable.pin_shadow);
markerImage.clearColorFilter();
markerImage.getDrawable().mutate().setColorFilter(color,PorterDuff.Mode.MULTIPLY);
markerRating.setText(文本);
markerLayout.measure(
View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED));
布局(0,0,markerLayout.getMeasuredWidth(),markerLayout.getMeasuredHeight());
最终位图=Bitmap.createBitmap(
markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight(),
位图.Config.ARGB_8888);
画布=新画布(位图);
markerLayout.draw(画布);
返回位图;
}
或者,我通过减少标记渲染来解决问题,如下所示:
我修改代码以强制对所有标记进行聚类,但屏幕上可见的标记除外
为此,我必须导入并修改maps utils库的原始代码,因为渲染仅在放大或缩小后发生,而不是在贴图移动后进行渲染
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
OwnRendring(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
... original code ...
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
boolean isInBounds = latLngBounds.contains(cluster.getPosition());
return !isInBounds || (cfgCluster && cluster.getSize() >= cfgClusterMin);
}
}
@Override
public void onCameraIdle() {
mClusterManager.cluster();
latLngBounds = mMap.getProjection().getVisibleRegion().latLngBounds;
}
显然,这不是我问题的正确答案,但对于任何有这个问题的人来说,这都是一个有效的选择,到目前为止还没有一个结论性的答案
***请有人在语法上纠正我的答案,因为英语不是我的母语
@SuppressLint("NewApi")
public void run() {
// if (clusters.equals(DefaultClusterRenderer.this.mClusters)) {
// mCallback.run();
// return;
// }
... original code ...
}