博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Unity--截取屏幕任意区域
阅读量:4654 次
发布时间:2019-06-09

本文共 874 字,大约阅读时间需要 2 分钟。

原地址:http://blog.csdn.net/tanmengwen/article/details/8501612

void Update () {        if(Input.GetKeyDown(KeyCode.A))        {            StartCoroutine(getScreenTexture());                           //unity 自带截屏,只能是截全屏            Application.CaptureScreenshot("shot.png");        }    }        public int capx=0;    public int capy=0;    public int capwidth=700;    public int capheight=500;    IEnumerator getScreenTexture()    {        yield return new WaitForEndOfFrame();        Texture2D t = new Texture2D(capwidth, capheight,TextureFormat.RGB24, true);//需要正确设置好图片保存格式          t.ReadPixels(new Rect(capx,capy,capwidth,capheight), 0, 0, false);//按照设定区域读取像素;注意是以左下角为原点读取        t.Apply();        //二进制转换        byte[] byt = t.EncodeToPNG();        File.WriteAllBytes(Application.dataPath  + Time.time + ".png", byt);    }

 

转载于:https://www.cnblogs.com/123ing/p/3799156.html

你可能感兴趣的文章
使用PagerSlidingTabStrip实现顶部导航栏
查看>>
调用摄像头和相册
查看>>
jQuery.事件对象
查看>>
CSS之属相相关
查看>>
整理了一下自己买过的计算机书
查看>>
解决py2exe error: MSVCP90.dll: No such file or directory
查看>>
java RSA实现私钥签名、公钥验签、私钥加密数据、公钥解密数据
查看>>
Erlang 练习题
查看>>
数据挖掘十大算法总结--核心思想,算法优缺点,应用领域
查看>>
GDALWarp设置GDALWarpOptions::dfWarpMemoryLimit过大时处理失败
查看>>
libubox组件(2)——blob/blobmsg (转载 https://segmentfault.com/a/1190000002391970)
查看>>
建立RSA协商加密的安全信道
查看>>
博客园的手机版(非官方) MVC+jQuery.Mobile
查看>>
jmeter在linux上运行
查看>>
js 逻辑与 逻辑或
查看>>
“请求/响应”模型
查看>>
【坑】重写一个vector
查看>>
【UOJ 55】志愿者选拔
查看>>
Python -- pandas
查看>>
jQuery 效果 - 淡入淡出
查看>>