Unity截图
什么都不说了,直接上代码。
using UnityEngine;
using System.Collections;
using System.IO; public class CutImage : MonoBehaviour
{
public Vector2 startPos; //鼠标开始位置
public Vector2 endPos; //鼠标结束位置
void Update()
{
if(Input.GetMouseButtonDown())
{
startPos = Input.mousePosition;
}
if(Input.GetMouseButtonUp())
{
endPos = Input.mousePosition;
StartCoroutine(CreateImage()); //当鼠标按键抬起,开始截图
} } IEnumerator CreateImage()
{
int width = (int)(endPos.x - startPos.x); //图片宽
int height = (int)(startPos.y - endPos.y); //图片高
Texture2D image = new Texture2D(width, height,TextureFormat.ARGB32, true); //创建一个纹理
Rect rect = new Rect(startPos.x, Screen.height - (Screen.height - endPos.y), width, height); //在屏幕上截取一个矩形
yield return new WaitForEndOfFrame(); //等待帧结束 image.ReadPixels(rect,, , true); //在屏幕的规定区域内读取像素
image.Apply(); //转化成图片
yield return image; byte[] bs = image.EncodeToPNG(); //把图片转化成二进制
File.WriteAllBytes(Application.dataPath + "/Image.png", bs); //把图片街道本地
yield return null;
} }
Unity截图的更多相关文章
- unity 截图 压缩 处理
/****************************************************** unity屏幕截图,并转换成Base64码* 作者: lyb* 日期:2017年7月25 ...
- Unity 截图选择框,中间全透明,边缘半透明
效果:点击白色框可拖拽选择区域 代码: using System.Collections; using System.Collections.Generic; using UnityEngine; u ...
- Unity项目接入应用宝SDK实现截图功能
Unity项目接入应用宝SDK实现截图功能 问题由来 点击应用宝悬浮窗 如图所示 左下角有一个截图按钮 需要解决那些问题 截图信息需要由游戏引擎提供 SDK获取截图信息为同步 但是Unity引擎没有提 ...
- Ubuntu 13.10 安装 Unity 8 试用截图
关于 Unity 8 有很多报道,Unity 8 相对于 Unity 7 变化相当大,这是 Ubuntu 团队打造的一款通用于 PC.手机.平板的桌面. Unity 8 已经登陆 ubuntu 13. ...
- Unity高像素截图
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/51386272 作者:car ...
- Unity协程截图,WWWForm、WWW配合上传
先说一下原理.. 截图有两种方法,第一种: Application.CaptureScreenshot(url); 这个API可以截全屏并保存到指定路径 这里我们不采用此方法 下面的代码采用第二种方法 ...
- 【Unity】鼠标划定范围然后截图~
有时候要重复用某一个场景的某一个角度,都过去好几步了结果总不能再把已经打乱的场景物体再移动回去吧.so~智慧的我完成了伟大的偷懒.截图保存,什么时候要看,直接上图片以假乱真棒棒哒~ 当然这个功能还能用 ...
- unity发布安卓 截图保存到本地
using System.IO; //获取系统时间并命名相片名 System.DateTime now = System.DateTime.Now; string times = now.ToStri ...
- Unity性能优化(2)-官方教程Diagnosing performance problems using the Profiler window翻译
本文是Unity官方教程,性能优化系列的第二篇<Diagnosing performance problems using the Profiler window>的简单翻译. 相关文章: ...
随机推荐
- 设置ListView的item多选
一,首先定义一个类来关联Adapter和Activity能够记住点击的位置 public class MyViewHoler{ public CheckBox cb; public TextView ...
- Time.deltaTime和Time.realtimeSinceStartup
private float f = 0f;void Update () { f += Time.deltaTime; Debug.LogError ("Time.delt ...
- C#4 for循环 迭代法 穷举法应用
for()循环. 四要素: 初始条件,循环条件,状态改变,循环体. 执行过程: 初始条件--循环条件--循环体--状态改变--循环条件.... 注意:for的小括号里面分号隔开,for的小括号后不要加 ...
- java之从字符串比较到==和equals方法区别
我们先看代码 String str1 = new String("hello"); String str2 = "hello"; System.out.prin ...
- bash基础知识
站在用户登录的角度来说,SHELL的类型:登录式shell: 正常通常某终端登录 su - USERNAME su -l USERNAME 非登录式shell: su USERNAME 图形终端下打开 ...
- [string]Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- grep 和 perl多个条件匹配
grep和perl多个条件匹配使用‘|’作为分割符号 grep -E 'abc|def' perl if(/abc|def/)
- 第一个MVC模型
根据慕课网的视频自学来的. 关于MVC的简介和一些常识:http://www.cnblogs.com/jobscn/archive/2011/11/08/2240725.html MVC模式 : MV ...
- QStringList不是简单重命名的便利类,而是提供了额外的函数,比如sort和join等等
以前一直以为就是重命名而已,原来还不是.QT真伟大,方便到家了.该有的,全都有现成的.
- Mozilla推荐的CSS书写顺序
//显示属性displaylist-stylepositionfloatclear //自身属性widthheightmarginpaddingborderbackground //文本属性color ...