/// <summary>
/// Screens the save.
/// </summary>
/// <returns>The save.</returns>
/// <param name="avatarName">Avatar name.</param>
public string ScreenSave (string avatarName)
{
//创建存放图片的目录
System.IO.Directory.CreateDirectory ("Assets/third_assets/UMA/Upload/AvatarPics/");
path = "Assets/third_assets/UMA/Upload/AvatarPics/" + avatarName + ".png";
//将videoSource指定为场景中的Camera对象
RenderTexture rt = new RenderTexture (width, height, 24);
videoSource = Camera.current;
if (videoSource == null) {
videoSource = Camera.allCameras [0];
}
videoSource.targetTexture = rt;
//初始化Texture2D对象,并赋值
//后面会将Texture2D对象(screenShot)转化为标准的png格式
Texture2D screenShot = new Texture2D (width, height, TextureFormat.ARGB32, false);
videoSource.Render ();
RenderTexture.active = rt;
screenShot.ReadPixels (new Rect (0, 0, width, height), 0, 0);
//销毁不需要的资源
videoSource.targetTexture = null;
RenderTexture.active = null;
Destroy (rt);
//获取图片数据流
byte[] bytes;
bytes = screenShot.EncodeToPNG ();
//保存图片到指定目录
System.IO.File.WriteAllBytes (path, bytes);
return path;
}
U3D 截图
最新推荐文章于 2024-06-04 10:04:13 发布