首页 > 系统 > Android > 正文

Android中将View的内容保存为图像的简单实例

2020-04-11 11:55:44
字体:
来源:转载
供稿:网友

原理:创建一个新的Bitmap,然后再根据它来创建一个Canvas,最后调用View的draw方法将View画到Canvas上,这样得到的Bitmap就是我们想要的。
代码:

复制代码 代码如下:

    public Bitmap createViewBitmap(View v) {
        Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
        Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        v.draw(canvas);
        return bitmap;
    }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表