码迷,mamicode.com
首页 > 移动开发 > 详细

unity发布安卓 截图保存到本地

时间:2016-12-12 09:33:02      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:llb   new   datetime   创建   roi   unit   mat   replace   平台   

using System.IO;

//获取系统时间并命名相片名
System.DateTime now = System.DateTime.Now;
string times = now.ToString ();
times = times.Trim ();
times = times.Replace ("/","-");
//文件名
string filename = "Screenshot"+times+".png";
//判断是否为Android平台
if (Application.platform == RuntimePlatform.Android) {

//截取屏幕
Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
//转为字节数组
byte[] bytes = texture.EncodeToPNG();

string destination = "/sdcard/DCIM/ARphoto";
//判断目录是否存在,不存在则会创建目录
if (!Directory.Exists (destination)) {
Directory.CreateDirectory (destination);
}
//文件路径
string Path_save = destination+"/" + filename;
//存图片
System.IO.File.WriteAllBytes(Path_save, bytes);
}

unity发布安卓 截图保存到本地

标签:llb   new   datetime   创建   roi   unit   mat   replace   平台   

原文地址:http://www.cnblogs.com/merveilleux/p/6163161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!