【发布时间】:2017-10-17 17:28:02
【问题描述】:
我正在使用 Unity 应用程序截屏
ScreenCapture.CaptureScreenshot ("screenshot.png", 2);
但是 ARKit 渲染的 AR 背景最终是完全黑色的,而其他游戏对象正确渲染(在黑色空间中浮动)。
其他人遇到过这个问题吗? 有已知的解决方法吗?
【问题讨论】:
标签: c# ios unity3d textures arkit
我正在使用 Unity 应用程序截屏
ScreenCapture.CaptureScreenshot ("screenshot.png", 2);
但是 ARKit 渲染的 AR 背景最终是完全黑色的,而其他游戏对象正确渲染(在黑色空间中浮动)。
其他人遇到过这个问题吗? 有已知的解决方法吗?
【问题讨论】:
标签: c# ios unity3d textures arkit
ScreenCapture.CaptureScreenshot 的错误太多。此时不要使用此功能在 Unity 中执行任何屏幕截图。不只是iOS,编辑器的这个功能也有bug。
这是该功能的翻版,可以截取 png、jpeg 或 exr 格式的屏幕截图。
IEnumerator CaptureScreenshot(string filename, ScreenshotFormat screenshotFormat)
{
//Wait for end of frame
yield return new WaitForEndOfFrame();
Texture2D screenImage = new Texture2D(Screen.width, Screen.height);
//Get Image from screen
screenImage.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
screenImage.Apply();
string filePath = Path.Combine(Application.persistentDataPath, "images");
byte[] imageBytes = null;
//Convert to png/jpeg/exr
if (screenshotFormat == ScreenshotFormat.PNG)
{
filePath = Path.Combine(filePath, filename + ".png");
createDir(filePath);
imageBytes = screenImage.EncodeToPNG();
}
else if (screenshotFormat == ScreenshotFormat.JPEG)
{
filePath = Path.Combine(filePath, filename + ".jpeg");
createDir(filePath);
imageBytes = screenImage.EncodeToJPG();
}
else if (screenshotFormat == ScreenshotFormat.EXR)
{
filePath = Path.Combine(filePath, filename + ".exr");
createDir(filePath);
imageBytes = screenImage.EncodeToEXR();
}
//Save image to file
System.IO.File.WriteAllBytes(filePath, imageBytes);
Debug.Log("Saved Data to: " + filePath.Replace("/", "\\"));
}
void createDir(string dir)
{
//Create Directory if it does not exist
if (!Directory.Exists(Path.GetDirectoryName(dir)))
{
Directory.CreateDirectory(Path.GetDirectoryName(dir));
}
}
public enum ScreenshotFormat
{
PNG, JPEG, EXR
}
用法:
void Start()
{
StartCoroutine(CaptureScreenshot("screenshot", ScreenshotFormat.PNG));
}
【讨论】: