Hello everyone I have a problem. My code saves or encodes Png photo very badly. It saves photo but it’s messed up for some reason. Tested on Android and on PC but its the same all time. Here is what I get:
I’m positive this is problem with not yielding – it has to do with the computer attempting to perform large operations like WriteAllBytes, on line 39, all in one frame. What I would suggest is that you make TakePhoto an IEnumerator, and try yielding after that line and some of the other large operations in that vicinity. Remember that you can Yield return StartCoroutine(“Somefunction”) to yield until the end of a function, and yield return 0 to skip a frame. But I would just try yield return new WaitForSeconds(1) after a few of the lines, and see if that fixes it – then start removing them. Let us know if that fixes it!
Thx @ImranZahid!, I had a similar issue, but wasn’t using the correct size, totally missed it here: How to save a snapshot of the WebcamTexture? - Unity Answers , though you both helped me finish this up… @wonker21 I would suggest removing the TextureFormat from your Texture2D declaration, and/or us TextureFormat.RGBA32, but I’m feeling like ImranZahid is right for your case too, where does photoSize come from? Try Grabbing the meshRenderer, material, mainTexture x & y:
MeshRenderer m = gameObject.GetComponent();
m.material.mainTexture.width & .height. GL