C# 使用Unity和ARKit进行屏幕截图
我在Unity应用程序中使用C# 使用Unity和ARKit进行屏幕截图,c#,ios,unity3d,textures,arkit,C#,Ios,Unity3d,Textures,Arkit,我在Unity应用程序中使用 screenscapture.captureshot(“screenshot.png”,2) 但是ARKit渲染的AR背景最终是完全黑色的,其他游戏对象渲染正确(漂浮在黑色空间中) 还有其他人遇到过这个问题吗? 是否有已知的解决方法?屏幕截图的错误太多。CaptureScreen shot。此时不要使用此功能在Unity中执行任何屏幕截图。不仅在iOS上,编辑器中的这个函数也存在bug 这里是该函数的翻拍版本,可以拍摄png、jpeg或exr格式的屏幕截图 IEnu
screenscapture.captureshot(“screenshot.png”,2)代码>
但是ARKit渲染的AR背景最终是完全黑色的,其他游戏对象渲染正确(漂浮在黑色空间中)
还有其他人遇到过这个问题吗?
是否有已知的解决方法?屏幕截图的错误太多。CaptureScreen shot
。此时不要使用此功能在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));
}