Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

Unity--截取屏幕任意区域

$
0
0

    直接上代码:

    using System.IO;

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);
    }


 http://blog.csdn.net/tanmengwen/article/details/8501612

作者:tanmengwen 发表于2013-1-14 16:35:53 原文链接
阅读:36 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>