【问题标题】:Could not allocate dup blob fd无法分配 dup blob fd
【发布时间】:2017-11-03 00:13:56
【问题描述】:

我的应用程序在地图上大约有 1,500 个标记,这些标记通过集群显示,以免应用程序过载。这些书签目前显示为 BitmapDescriptorFactory.defaultMarker ()

但是,当我修改每个点的代码以显示带有标记值的自定义位图时,只有少数设备出现此错误,其中包括 LG K10 LTE 和一些摩托罗拉。大多数电器工作正常。

当我使用这个函数时,在我完成渲染所有 1500 个标记之前,它会崩溃并出现以下错误:

“无法分配 dup blob fd。”

在对此错误的研究中,在我看来这是内存溢出,我应该将这些标记存储在 LRU 缓存中,但我无法与集群一起执行此操作。

有没有人遇到过这个问题,或者您有解决这个问题的想法/建议?

以下是位图渲染器代码sn-p:

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;
}

【问题讨论】:

    标签: android google-maps bitmap marker


    【解决方案1】:

    另外,我通过减少标记渲染来解决我的问题,如下所示:

    我修改代码以强制对所有标记进行聚类,但屏幕上可见的标记除外。

    为此,我不得不导入并修改 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;
    }
    

    在库 maps-utils(class DefaultClusterRenderer)中,我评论了这些行,因为当用户移动地图时它们返回时没有渲染集群:

            @SuppressLint("NewApi")
            public void run() {
    //            if (clusters.equals(DefaultClusterRenderer.this.mClusters)) {
    //                mCallback.run();
    //                return;
    //            }
    
                  ... original code ...
    
            }
    

    显然,这不是我问题的正确答案,但对于遇到此问题的任何人来说,它都是一个有效的替代方案,到目前为止还没有确凿的答案。

    *** 请有人在语法上纠正我的答案,因为英语不是我的母语。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 2021-01-20
      • 2019-07-19
      相关资源
      最近更新 更多