Keymaker
Keymaker

Reputation: 137

Take photo using webcam is giving black output[Unity3D]

I used the code given by @Bart in the Stackoverflow question Can I take a photo in Unity using the device's camera? with some modification. But the result is coming out to be a completely black photo.

I would like to add that the script is attached to a cube which has a renderer. Also renderer was deprecated hence I had to use GetComponents() for the same.

Upvotes: 5

Views: 2493

Answers (2)

Monika Torkowska
Monika Torkowska

Reputation: 11

Besides

yield return new WaitForEndOfFrame();

invoked in coroutine adding some delay can be required.

For me in avoiding black output works (not the most elegant solution):

yield return new WaitForEndOfFrame();
yield return new WaitForSeconds(1f); //Customize

Upvotes: 1

Everts
Everts

Reputation: 10701

I would think at the moment you take the shot, the rendering is not done since rendering happens late in the frame.

You should most likely use a coroutine and wait for the end of the frame

yield return new WaitForEndOfFrame();

or use the callback OnPostRender from the camera that is rendering the process.

Upvotes: 4

Related Questions