【发布时间】:2016-04-23 04:26:42
【问题描述】:
好的,我知道 canvas.toDataUrl() 会生成 png 格式的图像。但是,当我尝试从http://threejs.org/examples/#webgl_lines_sphere 获取图像时。我所看到的只是 chrome 上的黑色图像。复制这些步骤 -
1) 打开开发控制台并选择画布元素。
2)canvas = $0
3)context = canvas.getContext('webgl', {preserveDrawingBuffer: true})
4)img = canvas.toDataUrl()
5)document.write('<img src="'+img+'"/>')
图像是空白的。 但是,我尝试在链接http://threejs.org/examples/#canvas_geometry_cube 使用不同的画布。请按照以下步骤进行复制。
1) 打开开发控制台并选择画布元素。
2)canvas = $0
3)context = canvas.getContext('2d', {preserveDrawingBuffer: true})
4)img = canvas.toDataUrl()
5)document.write('<img src="'+img+'"/>')
这给出了预期的结果。为什么有区别,如何避免这种情况也检索第一张图像?
【问题讨论】:
标签: html canvas three.js webgl todataurl