为了账号安全,请及时绑定邮箱和手机立即绑定

Unity3d中的几种截图方法

Unity3d中的几种截图方法

缥缈止盈 2019-02-15 15:14:17
Unity3d中的几种截图方法
查看完整描述

1 回答

?
慕慕森

TA贡献1856条经验 获得超17个赞

第一种,用自带的API来做,灵活性一般:Application.CaptureScreenshot ("Screenshot.png");
第二种,读屏幕的图像并保存,需要在协程里面等待一帧,示例如下:
IEnumerator OnScreenCapture ()

{
yield return new WaitForEndOfFrame();//等待这一帧画完了才能截图
try
{
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D ( width, height, TextureFormat.RGB24, false);//新建一张图
tex.ReadPixels (new Rect (0, 0, width, height), 0, 0, true);//从屏幕开始读点
byte[] imagebytes = tex.EncodeToJPG ();//用的是JPG(这种比较小)
tex.Compress (false);
tex.Apply();
Texture2D mScreenShotImgae = tex;
File.WriteAllBytes ( @"E:\Screenshot.png", imagebytes);
}
catch (System.Exception e)
{
Debug.Log ("ScreenCaptrueError:" + e);
}
}
如果有路过的大神知道其他的截图方法,请一定要告知我,万分感谢。



查看完整回答
反对 回复 2019-02-17
  • 1 回答
  • 0 关注
  • 966 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信