canvas.toDataURL() returns a black image

Chinta Jagad picture Chinta Jagad · Jan 28, 2019 · Viewed 9.6k times · Source

We are developing a sample three.js application which shows a thumbnail. For any scene that we create, we require to take a screenshot of the canvas, for this purpose, we are using canvas.toDataURL("image/png"). For repeated invocations of the above function, it returns the same black image, despite elements being added to the canvas.

We are using WebGLRenderer and threejs r99

Live Canvas canvas.toDataURL()

I am using google chrome and threejs. Since the canvas context will be made by threejs itself, I cannot add that parameter (preserveDrawingBuffer) shown in the question Canvas toDataURL() returns blank image only in Firefox

Answer

Laxmikant Dange picture Laxmikant Dange · Jan 28, 2019

When you are calling WebGLRenderer, pass preserveDrawingBuffer:true. Here are list of parameters which you can configure.