Unity3d中的几种截图方法

Unity3d中的几种截图方法


喵喔喔
浏览 654回答 1
1回答

慕盖茨4494581

很抱歉所知甚少,目前我仅知道两种截图方式“第一种,用自带的API来做,灵活性一般:Application.CaptureScreenshot ("Screenshot.png");第二种,读屏幕的图像并保存,需要在协程里面等待一帧,示例如下:IEnumerator OnScreenCapture (){yield return new WaitForEndOfFrame();//等待这一帧画完了才能截图try{int width = Screen.width;int height = Screen.height;Texture2D tex = new Texture2D ( width, height, TextureFormat.RGB24, false);//新建一张图tex.ReadPixels (new Rect (0, 0, width, height), 0, 0, true);//从屏幕开始读点byte[] imagebytes = tex.EncodeToJPG ();//用的是JPG(这种比较小)tex.Compress (false);tex.Apply();Texture2D mScreenShotImgae = tex;File.WriteAllBytes ( @"E:\Screenshot.png", imagebytes);}catch (System.Exception e){Debug.Log ("ScreenCaptrueError:" + e);}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Unity 3D