Unity3D-截屏操作
来源:互联网 发布:淘宝怎样申请退款 编辑:程序博客网 时间:2024/06/07 15:10
private static string _TextureUrl; public static string TextureUrl { set { _TextureUrl = value; } get { if (_TextureUrl == null) { // "/sdcard/Pictures/Test"; #if UNITY_ANDROID && !UNITY_EDITOR string temp =Application.persistentDataPath; DirectoryInfo diInfo = new DirectoryInfo(temp); _TextureUrl=diInfo.Parent.Parent.Parent.Parent.FullName+"/Pictures/Test"; #elif UNITY_IPHONE && !UNITY_EDITOR _TextureUrl = Application.persistentDataPath+"/Test"; #else _TextureUrl = Application.dataPath + "/Test"; #endif System.IO.Directory.CreateDirectory(_TextureUrl); } return _TextureUrl; } }
public static string GetFileNameToTime { get { return "tb_" + DateTime.Now.ToFileTime().ToString() + ".jpg"; } }
public void ScreenShotStart (string parem) { Debug.Log ("This is param: " + parem); string fileName = ""; if (string.IsNullOrEmpty (parem)) fileName = AppConfig.TextureUrl + "/" + AppConfig.GetFileNameToTime; else fileName = AppConfig.TextureUrl + "/" + parem; StartCoroutine (CaptureScreenshot (MainCamera, fileName)); } /// <summary> /// 截图操作 /// </summary> /// <returns>The screenshot.</returns> /// <param name="mCamera">相机</param> /// <param name="mFileName">完整路径</param> IEnumerator CaptureScreenshot (Camera mCamera, string mFileName) { Rect rect = new Rect (); rect.width = Screen.width; rect.height = Screen.height; //等待渲染线程结束 yield return new WaitForEndOfFrame (); //初始化RenderTexture RenderTexture mRender = new RenderTexture ((int)rect.width, (int)rect.height, 0); //设置相机的渲染目标 mCamera.targetTexture = mRender; //开始渲染 mCamera.Render (); //激活渲染贴图读取信息 RenderTexture.active = mRender; Texture2D mTexture = new Texture2D ((int)rect.width, (int)rect.height, TextureFormat.RGB24, false); //读取屏幕像素信息并存储为纹理数据 mTexture.ReadPixels (rect, 0, 0); //应用 mTexture.Apply (); //释放相机,销毁渲染贴图 mCamera.targetTexture = null; RenderTexture.active = null; GameObject.Destroy (mRender); //将图片信息编码为字节信息 byte[] bytes = mTexture.EncodeToPNG (); //保存 File.WriteAllBytes (mFileName, bytes); yield return bytes; #if UNITY_IPHONE && !UNITY_EDITOR CallIosMeth.ShowImgToAlbum(mFileName); #endif }
/// <summary> /// IOS 保存相册操作 /// </summary> /// <param name="typeid">Typeid.</param> public static void ShowImgToAlbum (string path) { #if UNITY_IPHONE ImgToAlbum(path); #endif }
#if UNITY_IPHONE [DllImport ("__Internal")] private static extern void ImgToAlbum (string path); #endif
阅读全文
1 0
- Unity3D-截屏操作
- Unity3D截屏工具
- Unity3D 截屏功能
- Unity3d xml操作类
- Unity3d鼠标操作
- Unity3d读写文件操作
- unity3d各种OpenFileDialog操作
- unity3d各种OpenFileDialog操作
- unity3d各种OpenFileDialog操作
- unity3D的数据库连接操作
- unity3d各种OpenFileDialog操作
- unity3d各种OpenFileDialog操作
- unity3d---数据库基本操作
- Unity3D触摸操作
- Unity3d 中按钮操作
- unity3d各种OpenFileDialog操作
- Unity3D操作技巧
- unity3d各种OpenFileDialog操作
- TCP自连接问题
- 求幂函数
- okhttp 流程和优化的实现
- 1042. 字符统计
- 【猪八戒】- 2017年在线笔试“叠字问题”
- Unity3D-截屏操作
- std::vector<string>转string
- leetcode 129. Sum Root to Leaf Numbers 一个简单的DFS做法
- c++中模板使用时候typename和class的区别
- Kth Largest Element in an Array
- Oracle与MySQL的几点区别
- 合法的括号序列
- 图论Day3(模版-单源最短)
- Mysql数据库操作(一)----数据库(DDL)