博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unity 截图保存及显示
阅读量:4681 次
发布时间:2019-06-09

本文共 1394 字,大约阅读时间需要 4 分钟。

需要注意的是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

你可能感兴趣的文章
第三组的抓包作业
查看>>
ILNumerics项目的应用之线性方程
查看>>
django考点
查看>>
python-socket
查看>>
.NET 分布式技术比较
查看>>
SpringMVC视频
查看>>
Android中intent如何传递自定义数据类型
查看>>
Android蓝牙音乐获取歌曲信息
查看>>
android基础---->子线程更新UI
查看>>
SharedPreferences
查看>>
转载 线程池之ThreadPool类与辅助线程 - <第二篇>
查看>>
解决windows 10 9926 中vmware安装的虚拟机无法桥接上网的问题
查看>>
js获取元素样式
查看>>
合并排序(C语言实现)
查看>>
sql 计算两时间或日期 的相差的 年、 月、 日、时、分、秒,年、月、日分别的提取...
查看>>
HDU 1176免费馅饼 DP数塔问题转化
查看>>
十进制二进制转换
查看>>
shiro实战系列(七)之Realm
查看>>
数据库持久化比较
查看>>
超像素、语义分割、实例分割、全景分割 傻傻分不清?
查看>>