我是Unity的新手,我试图保存图像以获取它。我尝试使用Texture2D.ReadPixel的Application.CaptureScreenshot和方法,我尝试保存在/ datad / / / / / / / / emulated /中的persistentDataPath(/data/user/0/my.package.name/files/)中0 /下载。没有方法有效。在我的项目的每个清单中,我都有WRITE_EXTERNAL_STORAGE权限。如果我保存到持久数据,我发现它只找到了UnityAds的缓存,如果我保存到Download文件夹,我会被拒绝访问。
任何人都可以帮助我?
这是我的代码:
if(!System.IO.Directory.Exists("/sdcard/Download/"))
{
System.IO.Directory.CreateDirectory ("/sdcard/Download/");
}
if(!System.IO.Directory.Exists(Application.persistentDataPath))
{
System.IO.Directory.CreateDirectory (Application.persistentDataPath);
}
在我检查文件夹是否存在之前:
StartCoroutine(ScreenShot());
我用以下内容启动IEnumerator:
public function getEmployees() {
$this->db->where("employees.userID","$_SESSION['empnum']");
$this->db->join('times', 'employees.userID =times.empnum' as enm);
$this->db->join('designation', 'employees.designation_id = designation.designation_id' as desig); $query = $this->db->get();
return $query->result();
}
Now Try this function.
我做错了什么?
答案 0 :(得分:1)
这对我有用:
string destination = DateTime.Now.ToString ("yyyy-MM-dd-HHmmss") + ".png";
string fullDestination = Path.Combine (Application.persistentDataPath, destination);
Application.CaptureScreenshot (destination);
SharingWriter.WriteTextInstant ("Preparing...");
FileInfo fileInfo = new FileInfo(fullDestination);
while(fileInfo == null || fileInfo.Exists == false)
{
yield return null;
fileInfo = new FileInfo(fullDestination);
}
Application.CaptureScreenshot处理所有内容,无需担心读取像素和写入冗余的文件。然后在Coroutine中进行一段时间的循环,等待魔法发生!我用它来为移动设备创建屏幕截图共享功能。