Arcgis For Android 中MapView 截圖獲取Bitmap

weixin_33866037發表於2016-10-26

使用MapView時,擷取當前地圖,獲取Bitmap,方法如下:

    /**
     * mapView 截圖
     * @param v
     * @return
     */
    private Bitmap getViewBitmap(MapView v) {
        v.clearFocus();
        v.setPressed(false);
        // 能畫快取就返回false
        boolean willNotCache = v.willNotCacheDrawing();
        v.setWillNotCacheDrawing(false);
        int color = v.getDrawingCacheBackgroundColor();
        v.setDrawingCacheBackgroundColor(0);
        if (color != 0) {
            v.destroyDrawingCache();
        }
        v.buildDrawingCache();
        Bitmap cacheBitmap = null;
        while (cacheBitmap == null) {
            cacheBitmap = v.getDrawingMapCache(0, 0, v.getWidth(),
                    v.getHeight());
        }
        Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        v.destroyDrawingCache();
        v.setWillNotCacheDrawing(willNotCache);
        v.setDrawingCacheBackgroundColor(color);
        return bitmap;
    }

相關文章