Как сохранить захваченное фото из единства в Android Image Gallery? - PullRequest
0 голосов
/ 11 мая 2018

У меня есть действующий скрипт, который делает снимок с помощью камеры AR и сохраняет его в файлах данных Android, например:

    screenShotName = "Dorot" + System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".png";
    File.WriteAllBytes(Application.persistentDataPath + "/" + screenShotName, screenshot.EncodeToPNG());
    GameObject.Find("MainCanvas").GetComponent<Canvas>().enabled = true;

Как изменить persistentDataPath , указав правильный путь к галерее изображений Android.

Спасибо.

1 Ответ

0 голосов
/ 11 мая 2018

Я использую Плагин Unity Native Gallery , чтобы сделать то же самое.

Это мой код

public class ScreenshotTaker : MonoBehaviour
{
    public bool takingScreenshot = false;

    public void CaptureScreenshot()
    {
        StartCoroutine(TakeScreenshotAndSave());
    }

    private IEnumerator TakeScreenshotAndSave()
    {
        takingScreenshot = true;
        yield return new WaitForEndOfFrame();

        Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
        ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        ss.Apply();

        // Save the screenshot to Gallery/Photos
        string name = string.Format("{0}_Capture{1}_{2}.png", Application.productName, "{0}", System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
        Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name));
        takingScreenshot = false;
    }
}
...