C# 如何在Android图像库中保存unity拍摄的照片?

C# 如何在Android图像库中保存unity拍摄的照片?,c#,android,unity3d,augmented-reality,vuforia,C#,Android,Unity3d,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()); Ga

我有一个有效的脚本,可以用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;
screenShotName=“Dorot”+System.DateTime.Now.ToString(“yyyy-MM-dd-HH-MM-ss”)+“.png”;
File.writealBytes(Application.persistentDataPath+“/”+screenShotName,screenshot.EncodeToPNG());
GameObject.Find(“MainCanvas”).GetComponent().enabled=true;
如何使用Android Image Gallery的正确路径更改persistentDataPath

谢谢。

我以前也做同样的事情

这是我的密码

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

你可以像JackMini36在他的回答中所说的那样使用这个插件。或者你也可以编写一段代码来实现这一点

但挑战性的部分将是在Android设备上实现跨平台和许可问题。这篇文章很好地描述了在unity应用程序中如何在gallery中保存截图。

您无法将图片保存到Gallery,因为Gallery应用程序是一个应用程序,没有存储位置。Gallery应用程序只显示设备上的图像。。此外,您没有使用您现在使用的完整路径。谢谢,我理解,在我的手机中保存图像的当前路径是:my files\Internal storage\Android\data\com.CompanyName.AppName\files。在Windows上,图像保存在AppData文件夹中。
My files\Internal storage\Android\data\com.CompanyName.AppName\files。
抱歉,这是Android设备上不存在的路径。在设备上使用更好的文件资源管理器应用程序查找实际路径。