three.js toDataURL PNG为黑色 [英] three.js toDataURL PNG is black

查看:370
本文介绍了three.js toDataURL PNG为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用renderer.domElement.toDataURL("image/png")截取屏幕截图,并将其保存到文件中. 图像尺寸合适,但为黑色. 我已经打开了preserveDrawingBuffer.

I'm trying to grab a screenshot with renderer.domElement.toDataURL("image/png"), and save it to a file. The image is the right size, but it's black. I have preserveDrawingBuffer turned on.

我认为我正在正确解码和保存文件,因为当我将其十六进制转储时,我可以看到PNG格式的正确初始字符以及IHDR和IDAT块头.但是,结尾IEND丢失了.

I think I'm decoding and saving the file correctly, because when I hexdump it I can see the correct initial characters for the PNG format, as well as the IHDR and IDAT chunk headers. However the closing IEND is missing.

这里有任何已知问题吗?提示?如果需要的话,请使用最新的Windows 7/Firefox.

Any known issues here? Hints? Windows 7/Firefox up to date if it matters.

谢谢...(很抱歉,我是Three.js的新手)

Thanks... (Sorry if this is dumb, I'm very new to three.js)

推荐答案

我在Windows 7/Firefox中有类似的问题. PNG数据URL会被随机截断,或者比成功的PNG导出短得多的东西.尝试将该数据URL设置为image src会导致图像损坏"异常或FF.从某种意义上说,在呈现和获取数据URL之间设置一个小window.setTimeout(10ms)对我来说是有帮助的.也许Firefox需要JS引擎的休息,才能刷新画布的内部状态或某些奇怪的东西.

I had somewhat similar problems with Windows 7/Firefox. PNG Data URL's would be randomly truncated or something, much shorter than a successful PNG export. Trying to set that data url as image src resulted in "Image corrupt" exception or something in FF. As little sense it makse, setting a small window.setTimeout (10ms) between rendering and getting the data URL helped in my case. Maybe Firefox needs a rest from the JS engine before it refreshes some canvas internal state or something.. weird.

这篇关于three.js toDataURL PNG为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆