当前位置: 首页 > news >正文

Unity Android端截图保存并获取展示

截屏保存方法

    public static IEnumerator ScreenShot(string filePath, string fileName){yield return new WaitForEndOfFrame();Rect rect = new Rect(0, 0, Screen.width, Screen.height);Texture2D screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);screenShot.ReadPixels(rect, 0, 0);screenShot.Apply();byte[] bytes = screenShot.EncodeToPNG();if (!Directory.Exists(filePath))Directory.CreateDirectory(filePath);File.WriteAllBytes(filePath + "/" + fileName + ".png", bytes);
#if UNITY_EDITORAssetDatabase.SaveAssets();AssetDatabase.Refresh();
#endif}

以日期为名称调用

    public void TakeAScreenShot() {string englishTime = DateTime.Now.ToString(); //2000/9/27 1:27:28string chineseTime = string.Empty;string[] split1 = englishTime.Split('/'); //2000 - 9 - 27 1:27:28string[] split2 = split1[2].Split(' '); //27 - 1:27:28string[] split3 = split2[1].Split(':'); //1 - 27 - 28chineseTime += split1[0] + "年" + split1[1] + "月" + split2[0] + "日" + split3[0] + "时" + split3[1] + "分" + split3[2] + "秒";    StartCoroutine(UnityHelper.ScreenShot(UIPanel_ScreenShot.M_Path, chineseTime, false));}

获取截图

    private List<Texture2D> m_ScreenShotTextures;private void GetFilesInFolder(string folderPath){if (Directory.Exists(folderPath)){string[] currentFiles = Directory.GetFiles(folderPath);if (currentFiles.Length > 0){m_ScreenShotTextures = new List<Texture2D>();foreach (string filePath in currentFiles){
#if UNITY_EDITORif (filePath.EndsWith("png"))
#endifm_ScreenShotTextures.Add(ReadTexture(filePath));}m_ScreenShotTextures.Reverse();}}SetScreenShot();}private Texture2D ReadTexture(string filePath){Texture2D pathTex = new Texture2D(Screen.width, Screen.height);
#if UNITY_EDITORstring[] split1 = filePath.Split("\\"); //...... - ***.png
#elif UNITY_ANDROIDstring[] split1 = filePath.Split("/"); //...... - ***.png
#endifstring[] split2 = split1[split1.Length - 1].Split("."); // *** - pngpathTex.name = split2[0];byte[] bytes = File.ReadAllBytes(filePath);pathTex.LoadImage(bytes);pathTex.Apply();return pathTex;}

展示:把上面获取的结果进行展示即可

http://www.lryc.cn/news/421706.html

相关文章:

  • linux高级编程——文件IO
  • windows C++-在 C++/WinRT 中使用委托处理事件(下)
  • 【实用工具】Stirling-PDF: 优质开源的PDF处理工具/编辑工具-含入门安装教程
  • opencv 深度图视差图可视化案例
  • Golang | Leetcode Golang题解之第330题按要求补齐数组
  • 算法训练(leetcode)第五十二天 | Bellman_ford 队列优化算法(SPFA)、BF算法判断负回路、BF之单源有限最短路(有负回路)
  • SpringBoot中整合RabbitMQ(测试+部署上线 最完整)
  • 算法板子:线性DP——算出三角形中的最大路径值、求最长上升子序列、求最长公共子序列
  • 【C++】值传递
  • 工业三防平板助力MES系统打造工厂移动式生产管理
  • keepalived+nginx实现的简单高可用故障转移
  • openai api使用
  • 带你走进haproxy的世界
  • STM32--中断使用(超详细!)
  • 【深度学习实践】基于深度学习的图像去雾算法-ChaIR-实践
  • 《乳腺密度高的女性中,使用AI辅助的乳腺X线筛查与补充筛查超声的比较研究》| 文献速递-基于深度学习的乳房、前列腺疾病诊断系统
  • crm 销售管理系统有哪些?国内外排名前十盘点
  • package-lock.json 要提交到git吗?
  • 算法学习day32
  • 知识与智慧
  • 使用FFmpeg实现摄像头RTMP实时推流
  • 使用 LabVIEW 编程更改 IMAQ/IMAQdx 接口的相机文件
  • [后端代码审计] PHP 基础学习
  • 【OpenCV C++20 学习笔记】直方图计算-split, calcHist, normalize
  • js入门经典学习小结
  • nps内网穿透之——腾讯云服务器和linux虚拟机
  • 大数据知识点
  • 【计算机毕设项目】2025级计算机专业项目推荐 (前后端Web项目)
  • 【MySQL】2.MySQL实际操作
  • Winform画圆以及无边框窗体的移动