抓取webview时,没有显示view的内容是白色的
When capturing webview, content without displaying view is white
我有一个关于 Webview 的问题。
这是我的来源和结果。
private void saveDocumentImage() {
WebView wv = arrWebView.get(0);
wv.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int y=wv.getHeight();
Bitmap captureView = Bitmap.createBitmap(wv.getMeasuredWidth(), wv.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
wv.layout(0, 0, wv.getMeasuredWidth(), wv.getMeasuredHeight());
Canvas screenShotCanvas = new Canvas(captureView);
wv.draw(screenShotCanvas);
if (captureView != null) {
try {
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path, "temp");
if (!file.exists())
file.mkdirs();
fOut = new FileOutputStream(path + "/temp/test_0.jpg");
captureView.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
wv.setDrawingCacheEnabled(false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
wv.destroyDrawingCache();
captureView.recycle();
captureView=null;
}
这里和我的一样。
:
你无法截取 Web 视图和表面视图的屏幕截图,因为它们的内容已加载到它们的 holder 中,而 holder 不是视图。如果您找到方法,请分享它。一旦我对它做了一些研究并发现 this 但我还没有测试过它。尝试一下,如果它适合你,然后接受我的回答:D。祝你好运
我有一个关于 Webview 的问题。
这是我的来源和结果。
private void saveDocumentImage() {
WebView wv = arrWebView.get(0);
wv.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int y=wv.getHeight();
Bitmap captureView = Bitmap.createBitmap(wv.getMeasuredWidth(), wv.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
wv.layout(0, 0, wv.getMeasuredWidth(), wv.getMeasuredHeight());
Canvas screenShotCanvas = new Canvas(captureView);
wv.draw(screenShotCanvas);
if (captureView != null) {
try {
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path, "temp");
if (!file.exists())
file.mkdirs();
fOut = new FileOutputStream(path + "/temp/test_0.jpg");
captureView.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
wv.setDrawingCacheEnabled(false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
wv.destroyDrawingCache();
captureView.recycle();
captureView=null;
}
这里和我的一样。 :
你无法截取 Web 视图和表面视图的屏幕截图,因为它们的内容已加载到它们的 holder 中,而 holder 不是视图。如果您找到方法,请分享它。一旦我对它做了一些研究并发现 this 但我还没有测试过它。尝试一下,如果它适合你,然后接受我的回答:D。祝你好运