简体   繁体   中英

Screenshot not created | Unity3d, Android

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?

I haven't solved the issue using my own code.
The plugin suggested by Minzkraut (thank you!) is just too cheap, powerful and easy to use.

However the reason for my problem might have just been not setting Write access to
External (SDCard) in the Player settings , but I am not sure about that.

在此输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM