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

unity 截图保存及显示

需要注意的是win平台加载图片,用到 "file:///"

 参考来源  

 

StartCoroutine(SaveThePlayerColorImage(320));
//save the color image when the player pass the wall
    IEnumerator SaveThePlayerColorImage(int width)
    {
        float height=width/4*3;

        string dateTime = DateTime.Now.ToString("yyyyMMddhhmmss");// 20140904200210

        //saveThePlayerColorImagePath = Application.persistentDataPath + dateTime + ".png"; 
        saveThePlayerColorImagePath = Application.dataPath + "/PlayerImages/" + dateTime + ".png"; 
        yield return new WaitForEndOfFrame();
        Texture2D texture2D = new Texture2D(width, (int)height);

        texture2D.ReadPixels(new Rect(0, Screen.height - (int)height, width, height), 0, 0, false);
        texture2D.Apply();

        byte[] byt = texture2D.EncodeToPNG();

        System.IO.File.WriteAllBytes(saveThePlayerColorImagePath, byt);
   }

    //get the player color image
    IEnumerator ShowThePlayerColorImage()
    {
        string path = "file:///" + saveThePlayerColorImagePath.Replace(@"/", @"//");
        Debug.Log("path:OK="+path);

        www = new WWW(path);
        yield return www;

        if (www.error==null)
        {
            GameObject showColorImagetexture = GameObject.Find("ShowColorImage");
            showColorImagetexture.renderer.material.mainTexture = www.texture;
        }
        //image.mainTexture = www.texture;
    }

 

转载于:https://www.cnblogs.com/bkycjj/p/3994365.html

相关文章:

  • javacc学习
  • 《.NET 4.0面向对象编程漫谈》读者请进
  • 一个资源管理系统的设计--解析linux的cgroup实现
  • PHP安装memcache扩展接口步骤
  • 获取网页源代码
  • 怎样写linux下的USB设备驱动程序
  • SecureCRT配色方案
  • VIM 技巧 (一)全文统一添加
  • 我也站在潮头把潮弄
  • java 连接池的简单实现
  • Java源文件的编译、下载、解释和执行
  • 最小二乘法
  • 面向对象编程全面认识
  • 分布式文件系统名字空间实现研究
  • javaweb学习总结(二十二)——基于Servlet+JSP+JavaBean开发模式的用户登录注册
  • 【个人向】《HTTP图解》阅后小结
  • 【跃迁之路】【585天】程序员高效学习方法论探索系列(实验阶段342-2018.09.13)...
  • conda常用的命令
  • const let
  • ES学习笔记(10)--ES6中的函数和数组补漏
  • golang中接口赋值与方法集
  • js操作时间(持续更新)
  • Python实现BT种子转化为磁力链接【实战】
  • vuex 学习笔记 01
  • 关于extract.autodesk.io的一些说明
  • 算法-图和图算法
  • 微服务框架lagom
  •  一套莫尔斯电报听写、翻译系统
  • 硬币翻转问题,区间操作
  • ​io --- 处理流的核心工具​
  • ​linux启动进程的方式
  • ​第20课 在Android Native开发中加入新的C++类
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • #14vue3生成表单并跳转到外部地址的方式
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • #我与Java虚拟机的故事#连载15:完整阅读的第一本技术书籍
  • (007)XHTML文档之标题——h1~h6
  • (1)(1.13) SiK无线电高级配置(五)
  • (145)光线追踪距离场柔和阴影
  • (20)目标检测算法之YOLOv5计算预选框、详解anchor计算
  • (LeetCode C++)盛最多水的容器
  • (windows2012共享文件夹和防火墙设置
  • (非本人原创)史记·柴静列传(r4笔记第65天)
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理第3章 信息系统治理(一)
  • (亲测有效)解决windows11无法使用1500000波特率的问题
  • ***检测工具之RKHunter AIDE
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .NET 4.0网络开发入门之旅-- 我在“网” 中央(下)
  • .net core 依赖注入的基本用发
  • .net FrameWork简介,数组,枚举
  • .NET6使用MiniExcel根据数据源横向导出头部标题及数据
  • .NET企业级应用架构设计系列之应用服务器
  • .secret勒索病毒数据恢复|金蝶、用友、管家婆、OA、速达、ERP等软件数据库恢复
  • @Autowired注解的实现原理