我正在尝试使用此代码将相机的提要保存到 png,但它似乎无法正常工作:
void RecordAndSaveFrameTexture()
{
if (mXr.ShouldUseRealityRGBATexture())
{
SaveTextureAsPNG(mXr.GetRealityRGBATexture(), mTakeDirInfo.FullName + "/texture_" + mFrameInfo.mFrameCount.ToString() + ".png");
}
else
{
SaveTextureAsPNG(mXr.GetRealityYTexture(), mTakeDirInfo.FullName + "/texture_y_" + mFrameInfo.mFrameCount.ToString() + ".png");
SaveTextureAsPNG(mXr.GetRealityUVTexture(), mTakeDirInfo.FullName + "/texture_uv_" + mFrameInfo.mFrameCount.ToString() + ".png");
}
}
public static void SaveTextureAsPNG(Texture2D aTexture, string aFullPath)
{
byte[] bytes = aTexture.EncodeToPNG();
System.IO.File.WriteAllBytes(aFullPath, bytes);
Debug.Log("Image with Instance ID:" + aTexture.GetInstanceID() + "with dims of " + aTexture.width.ToString() + " px X " + aTexture.height + " px " + " with size of" + bytes.Length / 1024 + "Kb was saved as: " + aFullPath);
}
在非 ArCore android 上进行测试,我得到正确大小为 480 x 640 像素的黑色图像(带有随机彩色像素)。使用 ArCore,它是 0kb 黑色图像。