如何将Web视图转换为包括所有Web视图内容的位图

时间:2019-12-24 16:17:12

标签: java android android-studio webview bitmap

我正在使用此功能,但是可以给我截图,因此如果Web视图超过页面,我将无法在位图中获取所有内容

  public Bitmap createBitmapFromView(View v) {

    v.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT));

    v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(),
            v.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bitmap);
    v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    v.draw(c);
    return bitmap;
}

0 个答案:

没有答案