1 回答

TA貢獻(xiàn)1856條經(jīng)驗 獲得超17個贊
第一種,用自帶的API來做,靈活性一般:Application.CaptureScreenshot ("Screenshot.png");
第二種,讀屏幕的圖像并保存,需要在協(xié)程里面等待一幀,示例如下:
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);
}
}
如果有路過的大神知道其他的截圖方法,請一定要告知我,萬分感謝。
- 1 回答
- 0 關(guān)注
- 1299 瀏覽
添加回答
舉報