Unity截屏
方式一:直接使用unity自带的截图函数
Application.CaptureScreenshot(“imagename”);
保存路径:
- 在PC上保存路径为Application.dataPath(项目所在的路径)
- 在安卓或者Iphone平台上保存路径为Application.persistentDataPath(游戏里保存数据时放的一个持久数据目录)
优点:简单粗暴
缺点:PC、Mac上正常,但是在移动平台上会出现卡顿现象。
方式二:通过屏幕缓存转化为Png图片进行截图。
IEnumerator GetCapture()
{
//等待所有的摄像机跟GUI渲染完成
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
//如果 recalculateMipMaps 设置为真,这个贴图的mipmaps就会更新 如果 recalculateMipMaps设置为假,你需要调用Apply重新计算它们
tex.ReadPixels(new Rect(, , width, height), , , true);
byte[] imagebytes = tex.EncodeToPNG();//转化为png图
tex.Compress(false);//对屏幕缓存进行压缩
System.IO.File.WriteAllBytes(Application.dataPath + "/screencapture" + shotID + ".png", imagebytes);//存储png图
}
方式三:截图特定相机的可视图
public void ShotThree()
{
RenderTexture renderTex = new RenderTexture(Screen.width,Screen.height,);
if (shotCamera.targetTexture == null)
{
shotCamera.targetTexture = renderTex;
}
//手动渲染相机。
shotCamera.Render();
//所有的渲染将进入激活的RenderTexture,如果活动的RenderTexture为null,所有的东西都被渲染到主窗口
RenderTexture.active = renderTex;
Texture2D screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(new Rect(, , Screen.width, Screen.height), , );//
screenShot.Apply();
// 重置相关参数,以使用camera继续在屏幕上显示
shotCamera.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(renderTex);
// 最后将这些纹理数据,成一个png图片文件
byte[] bytes = screenShot.EncodeToPNG();
string filename = Application.dataPath + "/Screenshot.png";
shotID++;
System.IO.File.WriteAllBytes(shotPath + "/screencapture" + shotID + ".png", bytes);
}
扩展方式四:鼠标画区域截取,实现方式方式二,核心思想为记录鼠标按下跟抬起的点,算出矩形,读取该矩形范围内的像素保存为png图片。
Unity截屏的更多相关文章
- unity 截屏总结
转载与https://www.cnblogs.com/MissLi/p/8005342.html 1.针对指定的相机进行截屏 此中方式要添加yield return waitfortheEndofFr ...
- 关于Unity中GrabPass截屏的使用和Shader的组织优化
GrabPass截屏 可以用来截屏,截屏后把纹理传给下一个通道使用. 1:使用抓屏通道, GrabPass {} 或 GrabPass { “ 纹理名称”}; 使用GrabPass {}后,可以用_G ...
- Unity通过指定摄像机截屏
简介 介于照抄网上之前的截图教程,然后在实际应用过程中出现了一些小小的问题,修正了一下下,特此分享一下 PS:代码在后面 原理 原理很简单,就是将一个相机的内容渲染到一个贴图上,然后将贴图保存为图片 ...
- unity之截屏功能
1.全屏截图 方法一:在unity的API中,unity给我们提供了一个现成的API : Application.CaptureScreenshot(imagename). 但是这个API虽然简单 ...
- Unity图片处理类,包括压缩、截屏和滤镜
先上代码: 1 using System.Threading; using UnityEngine; using System.IO; using System.Collections; public ...
- Unity三种截屏方法(非自带API)
者利用了三种表现形式: 1,选择截图路径的方法 2,直接截取截屏的方法 3,截取鼠标圈选区域. 上代码,: 第一种是调用.net的类库,需要引用System.Windows.Forms.dll,在As ...
- Unity3d 截屏保存到相册,并且刷新相册
要做一个截图的功能,并且玩家可以在相册中看到. 做的时候遇到了三个问题: 1.unity自带的截图API,Application.CaptureScreenshot在Android上不生效 2.图片保 ...
- Linux系统安装MySql步骤及截屏
➠更多技术干货请戳:听云博客 如下是我工作中的记录,介绍的是linux系统下使用官方编译好的二进制文件进行安装MySql的安装过程和安装截屏,这种安装方式速度快,安装步骤简单! 需要的朋友可以按照如下 ...
- Android使用C++截屏并显示
使用android底层自带的截屏源码进行修改后,将截取屏幕的内容再次显示在屏幕上,使屏幕呈现出暂停的效果. android自带的截屏代码在android\JB\frameworks\base\cmds ...
随机推荐
- 值类型,引用类型,栈,堆,ref,out
在网上收集... C#的值类型,引用类型,栈,堆,ref,out C# 的类型系统可分为两种类型,一是值类型,一是引用类型,这个每个C#程序员都了解.还有托管堆,栈,ref,out等等概念也是每个C# ...
- 上传本地文件到HDFS
源代码: import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hado ...
- java 生成随机数
本段代码是生成的六位随机数.也可修改生成任意位随机数. int[] array = {0,1,2,3,4,5,6,7,8,9}; Random rand = new Random(); for (in ...
- git reset 理解
http://www.open-open.com/lib/view/open1397013992747.html 一般在工作中用的比较多的是: git reset --hard <commitI ...
- DOS命令行中的双引号
在DOS命令窗口下,运行C:\Program Files\WinRAR\WinRAR.exe,提示如下错误: 因为C:\Program Files\WinRAR\WinRAR.exe中含有空格,它被分 ...
- python 练习 28
ython pass是空语句,是为了保持程序结构的完整性. pass 不做任何事情,一般用做占位语句. Python 语言 pass 语句语法格式如下: pass 实例: #!/usr/bin/pyt ...
- python 练习 15
#!/usr/bin/python # -*- coding: UTF-8 -*- for i in range(1,10): for j in range(1,10): result = i * j ...
- spring来了-02-HelloWorld
spring的各个版本说明: 在3.0以下的版本,源码有spring中相关的所有包[spring功能+依赖包],如:2.5版本 在3.0以上的版本,源码中只有spring的核心功能包[没有依赖包],如 ...
- Remove Nth Node From End of List [LeetCode]
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- Sql server 日期函数和日期转换
时间函数 SQL Server Date 函数 下面的表格列出了 SQL Server 中最重要的内建日期函数: 函数 描述 GETDATE() 返回当前日期和时间 DATEPART(Type,dat ...