c# - 如何在 Android Image Gallery 中保存从 unity 拍摄的照片?

标签 c# android unity-game-engine augmented-reality vuforia

我有一个有效的脚本,可以用 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;

如何使用 Android 图片库的正确路径更改 persistentDataPath

谢谢。

最佳答案

我正在使用 Unity Native Gallery Plugin做同样的事情。

这是我的代码

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;
    }
}

关于c# - 如何在 Android Image Gallery 中保存从 unity 拍摄的照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50288337/

相关文章:

c# - 双泛型函数的语法糖

android - 单击按钮时如何检索按钮的名称(android)

ios - 当在 Unity 4.5.3f 中启用字节码剥离时,Parse 1.3 在 iOS 启动时抛出 EXC_BAD_ACCESS

c# - 如何通过 System.Data.SQLite 检索 F# 查询表达式的 SQL 查询字符串?

c# - 如何覆盖 winforms 组合框项目集合以实现特定接口(interface)

c# - System.Windows.Forms.Keys 枚举器中的 AltGr

java - 在 android 中使用 itext 生成 Pdf 用于 Bangla 文本

android - 将一个 mutableList 从 Activity A 传递到 Kotlin 中的 Activity B。

c# - Unity 修改启动屏幕分辨率

unity-game-engine - Holotoolkit 中的跨平台文件夹有什么作用?