apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.21k stars 19.6k forks source link

三星galaxy s11 Android Webview 截图echarts 区域显示空白 #11761

Closed vson1718 closed 4 years ago

vson1718 commented 4 years ago

Version

4.4.0

Steps to reproduce

1.使用webView打开Html(使用echarts4.4.0),显示正常(AndroidManifest.xml中设置属性Android:hardwareAccelerated=”false”。) 2.使用截图功能相关代码 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { WebView.enableSlowWholeDocumentDraw(); }

private Bitmap captureWebView(WebView webView){

Picture picture = webView.capturePicture();

int width = picture.getWidth();

int height = picture.getHeight();

if (width > 0 && height > 0) {

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

Canvas canvas = new Canvas(bitmap);

picture.draw(canvas);

return bitmap;

}

return null;

}

What is expected?

三星galaxy s11 使用 Webview 截图echarts 区域不显示空白

What is actually happening?

三星galaxy s11 使用 Webview 截图echarts 区域显示空白


截图WebView,分享到微信

echarts-bot[bot] commented 4 years ago

Hi! We've received your issue and please be patient to get responded. 🎉 The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that you have posted enough image to demo your request. You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to dev@echarts.apache.org. Please attach the issue link if it's a technical questions.

If you are interested in the project, you may also subscribe our mail list.

Have a nice day! 🍵

yufeng04 commented 4 years ago

This problem should have nothing to do with ECharts. You can look for better screenshots. Example

vson1718 commented 4 years ago

此问题应该与ECharts无关。您可以寻找更好的屏幕截图。

之前我也是这样认为的,但是为什么三星galaxy s11 出现这种问题,其他手机没有出现这个问题?

yufeng04 commented 4 years ago

It should be that when the screenshot function gets content of the canvas , it can't get the pixel content of the canvas. I don't think ECharts can solve this problem .

vson1718 commented 4 years ago

它无法获取画布的像素内容

这个点击事件获取WebView内容的(webView已经全部渲染出来了),所以你说的无法获取画布的像素内容是不存在的

pissang commented 4 years ago

@vson1718 渲染出来不一定就是能够拿到像素数据了,webgl 就有一个属性 preserveDrawingBuffer,设置了 false 就没法拿到像素 buffer 中的数据。

只有 s11 有这个问题可能是因为 s11 中 capturePicture 存在兼容性问题,@yufeng04 发的链接 https://stackoverflow.com/questions/20942623/which-can-replace-capturepicture-function/20963109#20963109 里也提到了这个方法已经是 deprecated

vson1718 commented 4 years ago

@vson1718 渲染出来不一定就是能够拿到像素数据了,webgl 就有一个属性 preserveDrawingBuffer,设置了 false 就没法拿到像素 buffer 中的数据。

只有 s11 有这个问题可能是因为 s11 中 capturePicture 存在兼容性问题,@yufeng04 发的链接 https://stackoverflow.com/questions/20942623/which-can-replace-capturepicture-function/20963109#20963109 里也提到了这个方法已经是 deprecated

使用以下代码依然无法解决问题

webView.measure(MeasureSpec.makeMeasureSpec( MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); webView.layout(0, 0, webView.getMeasuredWidth(), webView.getMeasuredHeight()); webView.setDrawingCacheEnabled(true); webView.buildDrawingCache(); Bitmap bm = Bitmap.createBitmap(webView.getMeasuredWidth(), webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas bigcanvas = new Canvas(bm); Paint paint = new Paint(); int iHeight = bm.getHeight(); bigcanvas.drawBitmap(bm, 0, iHeight, paint); webView.draw(bigcanvas);

pissang commented 4 years ago

这个问题跟 echarts 并没有关系,你可以随便自己建一个 canvas 试一下

如果要绕过的话,你可以试试使用 svg 模式渲染

var chart = echarts.init(dom, null, { renderer: 'svg' });