c# - 如何在 Android Image Gallery 中保存统一拍摄的照片?
问题描述
我有一个有效的脚本,可以用 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 Image Gallery 的正确路径更改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;
}
}
推荐阅读
- ios - (iOS react-native) Vimeo 视频在 react-native-webview 中全屏显示后的内容覆盖状态栏
- elasticsearch - Elasticsearch 聚合桶总是只显示 10 个结果
- node.js - 编译器无法从 node_modules/@types 中找到类型
- microsoft-graph-api - 在向 o365 日历创建新事件时向与会者发送通知电子邮件
- interpolation - 使用 openmodelica 进行插值的函数
- ios - 在 .xib 中使用自定义 UIView 作为 IBOutlet
- java - java中的函数结构与泛型
- visual-studio-2012 - 使用带有查找的聚合函数
- meshlab - 是否有在 meshlab 中扩张/侵蚀网格的功能?
- android - 为什么 YouTube API 需要这么长时间才能响应?