详细问题描述
[内容]
Android上使用webview的draw方法截图无法截取到canvas内容,而在ios上可以
重现步骤
[步骤]
在Android上使用webview的draw方法截取带有canvas内容的页面
[结果]
截图中没有canvas内容
运行环境
[系统版本]
小米pad Android 5.1
zuk z2 Android 7.1
[IDE版本]
HBuilder 8.8.0.201706142254
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<style>
#canvas {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 2;
}
#draw {
position: absolute;
z-index: 3;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas><br />
<button id="draw">点击截图</button>
</body>
<script type="text/javascript">
var c = document.getElementById("canvas");
c.width = window.innerWidth;
c.height = window.innerHeight;
var ctx = c.getContext("2d");
ctx.strokeStyle = "red";
ctx.strokeRect(20, 60, 300, 200);
document.addEventListener('plusready', function() {
var btn = document.getElementById('draw');
btn.addEventListener('click', function() {
var cw = plus.webview.currentWebview();
var bitmap = new plus.nativeObj.Bitmap();
cw.draw(bitmap, function(e) {
bitmap.save('_doc/save.jpg', {
overwrite: true
}, function(e) {
plus.runtime.openFile(e.target, {}, function(e) {
console.log("打开文件失败");
});
}, function(e) {
console.log("保存图片失败");
})
}, function(e) {
console.log("截图失败");
});
});
});
</script>
</html>
xiaoxiyao (作者)
所以说是bug咯,可以在文档里补充一下吗,避免更多人踩坑
2017-06-29 13:58