好的,我知道canvas.toDataUrl()会生成png格式的图像。但是,当我尝试从http://threejs.org/examples/#webgl_lines_sphere获取图像时。我所看到的只是镀铬的黑色图像。复制步骤-
1)打开开发者控制台,然后选择canvas元素。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)打开开发者控制台,然后选择canvas元素。2)canvas = $0
3)context = canvas.getContext('2d', {preserveDrawingBuffer: true})
4)img = canvas.toDataUrl()
5)document.write('<img src="'+img+'"/>')
这给出了预期的结果。为什么会有区别?又如何避免获取第一张图片?