据我所知,可以用下面的方法:
1 内置方法(简单有效,但是貌似不能够自定义存储路径等等):
Application.CaptureScreenshot ("Screenshot.png");
2 自己写一个方法读点(用的是类似流的思路还算比较灵活,但是存大图会卡,推荐图像类型慎重选择)
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(这种比较小)
//使用它压缩实时产生的纹理,压缩过的纹理使用更少的显存并可以更快的被渲染
//通过true为highQuality参数将抖动压缩期间源纹理,这有助于减少压缩伪像
//因为压缩后的图像不作为纹理使用,只是一张用于展示的图
//但稍微慢一些这个小功能暂时貌似还用不到
tex.Compress (false);
tex.Apply();
Texture2D mScreenShotImgae = tex;
File.WriteAllBytes ( @"E:\Screenshot.png", imagebytes);
}
catch (System.Exception e)
{
Debug.Log ("ScreenCaptrueError:" + e);
}
}
很抱歉所知甚少,目前我仅知道两种截图方式“
第一种,用自带的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);
}
}
如果有路过的大神知道其他的截图方法,请一定要告知我,万分感谢。
Photoshop|
Dreamweaver|
SVG|
WebGL|
Visual Studio|
PowerDesigner|
Eclipse|
Git|
Apache Ant|
Atom|
Composer|
CodeSmith|
Flex|
Gradle|
Maven|
Sublime Text3|
SVN|
Tableau|
Vim|
Chrome开发者工具|
OpenGL|
Unity|
Direct3D|
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....