I am trying to create a screenshot feature for my Android-Game in Unity .
I got this from code from various sources that and it should work, however I can't find the picture in the file-browser or the gallery for that matter.
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);
}
I want to save the screenshot to gallery. What do I need to do?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.