【问题标题】:Unity3D: Image is not saving in HDDUnity3D:图像未保存在硬盘中
【发布时间】:2014-11-20 08:57:40
【问题描述】:

我正在开发一个使用相机的移动应用程序。我的问题是拍摄的图像未保存在应用程序根文件夹中。这是用于捕获屏幕的代码的 sn-p。

Application.CaptureScreenshot("SavedScreen.png");

但这并没有在内部存储中保存任何内容。任何人都可以帮助我。 干杯。

【问题讨论】:

标签: image unity3d


【解决方案1】:

Application.CaptureScreenshot() 至少有 2 个微妙的使用问题浮现在脑海:

  1. 在 iOS 上它不会接受路径,它只会写入 Documents 文件夹。所以你的“SavedScreen.png”将在:

    Application.persistentDataPath + "/screenshot.png";

  2. 它是异步的,因此文件将需要几帧(如果不是一秒钟)来写入文件系统。它不会告诉你什么时候完成。

我更喜欢 ReadPixels 的完全控制,但如果你想使用 CaptureScreenshot,你应该等待至少 2 秒才能访问文件:

void CaptureScreenshot()
{
  StartCoroutine(CaptureScreenshotCo());
}

IEnumerator CaptureScreenshotCo()
{
  string file = "screenshot.png";
  string path = string.Format("{0}/{1}", Application.persistentDataPath, file);

  // capture screenshot async 
  Application.CaptureScreenshot(file);

  // wait for file to be saved
  yield return new WaitForSeconds(2f);

  // now do something with file...
}

【讨论】:

    猜你喜欢
    • 2011-02-08
    • 2015-05-16
    • 1970-01-01
    • 2017-08-24
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多