Android 自定义View转Bitmap

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34476727/article/details/83008502

最近在最CAD图,需要建立完对相应的设备然后保存一份截图,思前想后还是把自定义的View转为Bitmap 的方法,我自定义的是SurfaceView 上代码吧:

/**
     *   view转Bitmap
     * @param mGraphyView  SurfaceView
     * @return
     */
    private Bitmap convertViewToBitmap(SGraphyView mGraphyView) {
        mGraphyView.buildDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(mGraphyView.getWidth(), mGraphyView.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        mGraphyView.drawScene(canvas);
        return bitmap;
    }

其实View和SurfaceView只是调用.drawScene()和.draw()的区别

猜你喜欢

转载自blog.csdn.net/qq_34476727/article/details/83008502