【发布时间】:2021-06-09 11:50:19
【问题描述】:
我正在尝试在 AR 应用中捕捉相机在手机中看到的内容并拍照。我发现是截取设备的屏幕截图,然后将其保存为图像。但是,我想截取相机看到的而不是屏幕的屏幕截图。即没有在应用程序中创建任何 2D 或 3D 元素。纯粹是相机看到的。我该怎么做?
public void Start() {
StartCoroutine ("SaveImage");
}
WaitForEndOfFrame frameEnd = new WaitForEndOfFrame ();
IEnumerator SaveImage() {
// Create a texture the size of the screen, RGB24 format
int width = Screen.width;
int height = Screen.height;
yield return frameEnd;
var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
// Read screen contents into the texture
tex.ReadPixels (new Rect (0, 0, width, height), 0, 0);
tex.Apply ();
byte[] bytes = tex.EncodeToPNG ();
Destroy (tex);
var form = new WWWForm ();
form.AddField ("plant", plantComponentID);
form.AddBinaryData ("image", bytes, "screenShot.png", "image/png");
yield return null;
}
【问题讨论】:
-
好吧,据我所知,目前你做的是 excat 对面......你只考虑 Unity 渲染的内容,而不是任何输入摄像头......
-
@derHugo 那么我应该在截屏时禁用场景中的任何活动 UI 元素吗?
-
不...我的意思是没有实际硬件相机的视频流输入...您只存储在 Unity 中渲染的任何内容(2D/3D 内容).. 见为存储实际硬件相机图片提供完整解决方案的重复链接
-
@derHugo 啊,好的,谢谢,我会检查一下。