[英]Screenshot not created | Unity3d, Android
我正在嘗試為Unity中的 Android游戲創建一個屏幕截圖功能。
我從各種來源的代碼中得到了這個,它應該可以工作,但是我無法在文件瀏覽器或圖庫中找到相關的圖片。
void capture(){
foreach (GameObject i in hideOnCapture) {
i.SetActive (false);
}
//Application.CaptureScreenshot ("screenshot_" + DateTime.Now.ToString ("yyyyMMdd-hhmmss") + ".jpg");
StartCoroutine(ScreenshotEncode ());
foreach(GameObject i in hideOnCapture) {
i.SetActive (true);
}
}
IEnumerator ScreenshotEncode() {
string save_Address = "screenshot_" + DateTime.Now.ToString ("yyyyMMdd-hhmmss");
Texture2D texture1;
byte[] bytes;
yield return new WaitForEndOfFrame ();
texture1 = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
texture1.ReadPixels (new Rect (0 , 0, Screen.width, Screen.height), 0, 0);
texture1.Apply ();
yield return 0;
bytes = texture1.EncodeToPNG ();
File.WriteAllBytes ("/mnt/sdcard/DCIM/" + save_Address + ".jpg", bytes);
}
我想將截圖保存到圖庫。 我需要做什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.