标签:byte sharp tst string new width hmm system etop
private void CapturePhoto() { //图片存储的位置 string rootPath = @"d:\photo-whzq\"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(rootPath); } string filename = System.DateTime.Now.ToString("yyyyMMddHHmmssms") + ".png"; capturePicPng(rootPath + filename); string filefullname = rootPath + filename; ; PlayerPrefs.SetString(IMAGEFILE, filefullname); } public void capturePicPng(string _filePath) { FacePhoto.GetComponent<FaceDetection>().capturePicPng(_filePath); } //保存图片 private IEnumerator getTexture(string _filePath, byte _type) { yield return new WaitForEndOfFrame(); //相当于一个画布 Texture2D t = new Texture2D(1920, 1080, TextureFormat.RGBA32, false); //相当于在画布上画画 //读取屏幕的局部像素信息 t.ReadPixels(new UnityEngine.Rect(0, 0, Screen.width, Screen.height), 0, 0, true); t.Apply(); if (0 == _type) { byte[] byt = t.EncodeToJPG(); //将byte[]全部写入到文件 File.WriteAllBytes(_filePath, byt); } if (1 == _type) { byte[] byt = t.EncodeToPNG(); File.WriteAllBytes(_filePath, byt); } cameraTexture.Play(); } /// 拍照PNG /// /// public void capturePicPng(string _filePath) { ///< 正在录屏,直接返回 if (/*bIsSeriousCapture ||*/ null == cameraTexture) { return; } if (null != cameraTexture && !cameraTexture.isPlaying) { return; } cameraTexture.Pause();//停止摄像头 StartCoroutine(getTexture(_filePath, 1)); }
标签:byte sharp tst string new width hmm system etop
原文地址:https://www.cnblogs.com/clhxxlcj/p/10972615.html