Example #1
0
        /// <summary>
        /// Gets single camera frame in Texture2D format.
        /// Texture2D will have WebCamTexture's dimension and TextureFormat of RGBA32.
        /// </summary>
        /// <param name="webTex">WebCamTexture from which Texture2D will be created.</param>
        /// <param name="tex">Texture2D into which WebCamTexture contents will be copied. Will be resized to fit.</param>
        public static void GetWebCamTexture2D(WebCamTexture webTex, ref Texture2D tex)
        {
            if (webTex.isPlaying)
            {
                if (tex.width != webTex.width || tex.height != webTex.height ||
                    tex.format != TextureFormat.RGBA32)
                {
                    tex.Resize(webTex.width, webTex.height, TextureFormat.RGBA32, false);
                }

                CvConvert.WebCamTextureToTexture2D(webTex, ref tex);
            }
        }