首页 > 其他 > 详细

u3d摄像机截图

时间:2017-04-24 20:58:56      阅读:233      评论:0      收藏:0      [点我收藏+]
方法一:
Application.CaptureScreenshot("Screenshot.png", 0); 

方法二:
/// <summary>
/// Captures the screenshot2.
/// </summary>
/// <returns>The screenshot2.</returns>
/// <param name="rect">Rect.截图的区域,左下角为o点</param>
Texture2D CaptureScreenshot2(Rect rect)
{
// 先创建一个的空纹理,大小可根据实现需要来设置,Scene.width,Scene,height获取全屏
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24,false);

// 读取屏幕像素信息并存储为纹理数据,
screenShot.ReadPixels(rect, 0, 0);
screenShot.Apply();

// 然后将这些纹理数据,成一个png图片文件
byte[] bytes = screenShot.EncodeToPNG();
string filename = Application.dataPath + "/Screenshot.png";
System.IO.File.WriteAllBytes(filename, bytes);
UnityEngine.Debug.Log(string.Format("截屏了一张图片: {0}", filename));

// 最后,我返回这个Texture2d对象,这样我们直接,所这个截图图示在游戏中,当然这个根据自己的需求的。
return screenShot;
}
方法三:
public void shotPic()
{

var cam = gameObject.GetComponent<Camera>();
    var renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
cam.targetTexture = renderTexture;
cam.Render();

// 激活这个renderTexture, 并从中中读取像素。
RenderTexture.active = renderTexture;
Texture2D screenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
screenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
screenshot.Apply();

// 重置相关参数,以使camera继续在屏幕上显示
cam.targetTexture = null;
RenderTexture.active = null;

//Encode screenshot to PNG
byte[] bytes = screenshot.EncodeToPNG();
UnityEngine.Object.Destroy(screenshot);
File.WriteAllBytes(imagesPath + setPicName("test") + ".png", bytes);

}

u3d摄像机截图

原文:http://www.cnblogs.com/leeplogs/p/6758851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!