Quantcast
Channel: Latest Questions by Lunaria
Viewing all articles
Browse latest Browse all 24

How to plot the script asynchronously?

$
0
0
Hello, developers I'm going on my project which webcam shows view and captures its image when some frames reaches. But there's a problem. When **capturing process** goes on, **showing process** stops, and when **capturing** is done, **showing** also restarts. So it looks so oddly. So, I thought it would be done with threading or async. But Unity doesn't support multi-threading programming, nor async. Instead of those, many people say to use coroutine. I know how to use coroutine, but I don't know how to apply to my case. void TakeScreenShot() { Texture2D snap = new Texture2D(1280, 720, TextureFormat.RGB565, false); snap.SetPixels(back.GetPixels()); snap.Apply (); bmpz = snap.EncodeToPNG (); System.IO.MemoryStream ms = new System.IO.MemoryStream (bmpz); ms.Seek (0, System.IO.SeekOrigin.Begin); Image _bmp = Bitmap.FromStream (ms); _bmp.Save (_SavePath + "Image.bmp", ImageFormat.Bmp); ms.Close (); } void Start () { WebCamDevice[] devices = WebCamTexture.devices; WebCamTexture back = new WebCamTexture (devices[0].name, 1280, 720); back.Play(); renderer.material.mainTexture = back; } . . . void Update(){ if ((frameCounter % 150 == 0){ TakeScreenShot(); << **problem begins** } . . . } or is it possible that switch main thread to background thread, while screenshot thread to main thread? Any suggestion would be my help! Thanks for reading!

Viewing all articles
Browse latest Browse all 24

Trending Articles