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

Unity3d中的几种截图方法

Unity3d中的几种截图方法

喵喔喔 2018-12-30 00:00:34
Unity3d中的几种截图方法
查看完整描述

1 回答

?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

很抱歉所知甚少,目前我仅知道两种截图方式“
第一种,用自带的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-01-16
  • 1 回答
  • 0 关注
  • 642 浏览

添加回答

举报

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