1 回答

TA貢獻1850條經驗 獲得超11個贊
很抱歉所知甚少,目前我僅知道兩種截圖方式“
第一種,用自帶的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);
}
}
- 1 回答
- 0 關注
- 723 瀏覽
添加回答
舉報