屏幕截图 take screenshot
ScreenCapture.CaptureScreenshotAsTexture
yield return new WaitForEndOfFrame();
var screenShotTexture = ScreenCapture.CaptureScreenshotAsTexture();
// 相比CaptureScreenshot,可以使用自定义路径保存图片
byte[] bytes = screenShotTexture.EncodeToPNG();
var filePath = $"Assets/test.png";
File.WriteAllBytes(filePath, bytes);
RenderTexture
获得RenderTexture
方式一
var renderTexture = RenderTexture.GetTemporary(Screen.width, Screen.height, 32, GraphicsFormat.R8G8B8A8_UNorm); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture);
方式二
var screenRenderTexture = new RenderTexture(width, height, 0, GraphicsFormat.R8G8B8A8_UNorm);var originTargetTexture = camera.targetTexture;camera.targetTexture = screenRenderTexture;camera.Render();camera.targetTexture = originTargetTexture;
异步取得渲染数据:
UnityEngine.Rendering.AsyncGPUReadback.Request
传入RenderTexture、TextureFormat。注意这里的 TextureFormat 和 申请RenderTexture的 GraphicsFormat 的数据格式要一致,比如TextureFormat是 TextureFormat.RGBA32,GraphicsFormat 是 GraphicsFormat.R8G8B8A8_UNormprivate GraphicsFormat _graphicsFormat = GraphicsFormat.R8G8B8A8_UNorm; private TextureFormat _textureFormat = TextureFormat.RGBA32;public void TakeScreenShot(Camera camera, string path) {// 设置camera.targetTexture为screenRenderTexture来将当前颜色缓冲输出到RenderTexture上,之后再重置相机设置var screenRenderTexture = new RenderTexture(width, height, 0, _graphicsFormat);var originTargetTexture = camera.targetTexture;camera.targetTexture = screenRenderTexture;camera.Render();camera.targetTexture = originTargetTexture;UnityEngine.Rendering.AsyncGPUReadback.Request(screenRenderTexture, 0, _textureFormat, OnCompleteReadback); }void OnCompleteReadback(UnityEngine.Rendering.AsyncGPUReadbackRequest request) {if (request.hasError){Debug.Log("GPU readback error detected.");return;}byte[] colors = request.GetData<byte>().ToArray();// 异步写入方法,不阻塞主线程,ImageConversion.EncodeArrayToPNG是线程安全的所以不会报 must run in main thread 的错误Task.Run(() => File.WriteAllBytes(_filePath, ImageConversion.EncodeArrayToPNG(colors, _graphicsFormat, width, height))); }
此方法截图是在其他线程异步写入,不阻塞主线程
参考:https://stackoverflow.com/questions/62864092/unity-extracting-camera-pixel-array-is-incredibly-slow
http://www.taodudu.cc/news/show-3204018.html
相关文章:
- 17-截图screenshot
- Linux screenshot
- linux 怎么卸载gnome-screenshot,史上最全的使用 gnome-screenshot 获取屏幕快照指南
- Appium-Screenshot(截图)
- Splinter入门(十一) Screenshot 截图
- 屏幕截图--Take-ScreenShot分析
- pyautogui.screenshot()详解
- ABBYY Screenshot Reader功能详解
- linux 怎么卸载gnome-screenshot,Ubuntu 18.04下开启gnome-screenshot截图工具
- 20170502-Linux 截屏完全指南(gnome-screenshot)
- linux截图工具带编辑器,Screenshot Editor
- SystemUI之ScreenShot
- screenshot python_python 截图screenshot处理
- screenshot python_Selenium3+python异常后截图(screenshot)
- Screenshot
- Ubuntu 截图快捷键 gnome-screenshot 使用
- 分享屏幕截图ScreenShot方法总结
- css单双行样式
- JQ单双引号转义
- Latex文档单双栏设置
- js的单双引号嵌套问题
- 单双引号嵌套问题
- 单双精度区别
- js的单双引号
- if判断单双分支判断
- Linux单双引号嵌套引发的小问题
- 实现单双链表反转
- 单双链表的操作
- PHP判断单双
- 单双工通信解析
屏幕截图 take screenshot相关推荐
- VB代码实现屏幕截图(Screenshot功能)
采用的模拟按键(vbKeySnapshot)的方法实现,根据网上的代码改的,非常简单 API声明 Private Declare Sub keybd_event Lib "user32&qu ...
- android xwalkview 截屏,如何在Cordova中为你的应用创建屏幕截图
本文概述 尽管要求在应用程序中创建屏幕截图并不常见, 但是创建详细的错误报告(由用户甚至自动生成)可能会很有用.在本文中, 你将学习如何在cordova应用程序中轻松创建屏幕截图. 要求 为了在你的应 ...
- windows截图快捷键_使用快捷键打开并使用Windows截图工具
windows截图快捷键 Snippingtool used used to take screenshot in windows operating systems. Snipping tool i ...
- python识别图片文字、并返回文字坐标_PyAutoGui 图片识别+定位+截图函数文档
前言: 本章节有个非常重要的函数 locateCenterOnScreen! 如果你有一个图像文件,你可以在屏幕上直观地定位一些东西. 它直接返回x,y坐标点,返回值可以给click() PyAuto ...
- pyautogui使用经验
Pyautogui是一个Python库,它提供了一种简单而有效的方法来模拟用户在计算机上的鼠标和键盘操作.这个库可以用来自动化计算机上的任务,例如自动化测试.数据录入.屏幕捕捉等.在本篇文章中,我们将 ...
- 【测试开发】web 自动化测试 --- selenium4
目录 1. 什么是自动化为什么要做自动化 2. 为什么选择selenium作为我使用的web自动化工具 3. 什么是驱动?驱动的工作原理是什么 5. 第一个自动化程序演示 6. selenium基本语 ...
- 渗透杂记-2013-07-10
好几天没有写新文章了,今天出差难得清静,更新一篇. 1.首先用nmap获取一下在线信息,结果如下 1 namp -sP 192.168.16.0/24 总共有22个IP地址存活,总会有一些肥羊的. 2 ...
- 怎么从简历看候选人性格_我从拒绝设计候选人中学到的东西以及您不应该做的申请人...
怎么从简历看候选人性格 重点 (Top highlight) 用户体验设计 (UX Design) I get it. We all dream about that one company wher ...
- PyAutoGUI 使用介绍
这个 python 库是我用的比较多的第三方库了,因为它能帮我自动化操作许多事情,而且跨平台,非常好用.可以说是 python 中的按键精灵了.它不仅可以操作鼠标,还能操作键盘,屏幕截图,还能生成一些 ...
最新文章
- 有一间计算机教室英语,妙手巧动微机教室实施外语视听教学
- [20150608]dbms_random.value.txt
- 【转载】eclipse常用插件在线安装地址或下载地址
- c语言iota怎么用,C++ std::iota用法及代码示例
- 关于我对于写博客写文章的理解
- 如何用while循环输出十行十列变色★☆
- 《金领简历》精华 创业公司 面试机会 简历
- 一张模板替代数百Excel,这个工具让报表工作自动进行
- 各浏览器驱动下载地址及selenium配置
- conime.exe
- 完全背包问题(Java)
- 三大运营商的云计算之殇
- actions的使用详解
- MQL5: 通过反向持仓来平仓
- Oracle如何根据一个日期计算同比环比的日期
- Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
- GVM-11 centos8 源码安装指南(OpenVas)
- 数据中心双活该如何构建
- 高二会考计算机分数,会考成绩abcd各是多少分 会考成绩对高考有影响吗
- 22-08-08 西安 尚医通(04)MongoDB命令、MongoTemplate、MongoRepository