c# - 在 Unity 中截取没有 UI 元素的屏幕截图
问题描述
我正在尝试在 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;
}
解决方案
有趣的问题。
我会尝试设置一个RenderTexture,并告诉场景中的相机对其进行渲染。然后我会尝试使用 ImageConversion类将我的相机眼睛截图保存到文件中。
这正是我的尝试。不确定这是否是正确的方法,所以提供它以防万一。如果您尝试一下,我很高兴知道您尝试的结果:)
推荐阅读
- laravel - Laravel 并选择添加选项
- vb.net - 如何只保留第一个字符
- php - $_FILES 键用于构建 PSR-7 上传文件列表
- c++ - 使用 std::chrono::steady_clock 在线程/异步中对代码进行基准测试
- php - Base64_decode 用于表单输入的 json 值
- php - 如何在 symfony2 服务中使用多个参数
- java - 使用 PHP(可能是使用 shell_exec() 函数的命令行),如何确定 Java 应用程序/jar 文件当前是否正在运行?
- node.js - 用swagger装饰器嵌套js,重新装饰方法
- react-native - 从 reducer 获取数据到 FlatList 组件
- angular - 如何为 forkJoin 响应设置实名?