未创建屏幕截图 | Unity3d,Android
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);
}
我想将屏幕截图保存到图库。我需要做什么?
我正在尝试为 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);
}
我想将屏幕截图保存到图库。我需要做什么?