当前位置 : 主页 > 编程语言 > c++ >

android WebView 网页转图片

来源:互联网 收集:自由互联 发布时间:2021-07-03
Utils //记得在Activity中createView前加这句代码 /* if (Build.VERSION.SDK_INT = Build.VERSION_CODES.LOLLIPOP) { WebView.enableSlowWholeDocumentDraw(); } */ public static Bitmap capture(WebView webView) { Picture picture = webView.ca
Utils
//记得在Activity中createView前加这句代码
    /*
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            WebView.enableSlowWholeDocumentDraw();
        }
    */
 public static Bitmap capture(WebView webView) {
        Picture picture = webView.capturePicture();
        int width = picture.getWidth();
        int height = picture.getHeight();
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
        return bitmap;
    }
网友评论