Unity中文件流和WWW的方式加载图片
来源:互联网 发布:java和hadoop 编辑:程序博客网 时间:2024/05/22 17:19
private Image image; private string loadPath = "Assets/StreamingAssets" + "/Desert.png"; string picPathwww = "Desert.png"; void Start() { image = this.GetComponent<Image>(); LoadByIO(); // LoadByWWW(); } private void LoadByIO() { double startTime = (double)Time.time; using (FileStream fileStream = new FileStream(loadPath, FileMode.Open, FileAccess.Read)) { fileStream.Seek(0, SeekOrigin.Begin); byte[] bytes = new byte[fileStream.Length]; fileStream.Read(bytes, 0, (int)fileStream.Length); int width = 300; int height = 372; Texture2D texture = new Texture2D(width, height); texture.LoadImage(bytes); Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); image.sprite = sprite; startTime = (double)Time.time - startTime; Debug.Log("IO加载用时:" + startTime); } } private void LoadByWWW() { StartCoroutine(Load()); } IEnumerator Load() { double startTime = (double)Time.time; WWW www = new WWW("file://" + Application.streamingAssetsPath + "/Desert.png"); yield return www; if (www != null && string.IsNullOrEmpty(www.error)) { Texture2D texture = www.texture; Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); image.sprite = sprite; startTime = (double)Time.time - startTime; Debug.Log("wwww加载用时:" + startTime); } }结果比较 传统的IO读取方式比较快。
1 1
- Unity中文件流和WWW的方式加载图片
- Unity 中WWW加载 AssetBundle---中文路径
- unity通过WWW方式加载.obj文件
- javaIO流中文件的拷贝和图片的拷贝
- Unity的WWW网络动态加载和储存在本地
- Unity的WWW网络动态加载和储存在本地
- Unity的WWW网络动态加载和储存在本地
- Unity的WWW网络动态加载和储存在本地
- Unity资源处理机制(Assets/WWW/AssetBundle/...)读取和加载资源方式详解
- Unity资源处理机制(Assets/WWW/AssetBundle/...)读取和加载资源方式详解
- Unity资源处理机制(Assets/WWW/AssetBundle/...)读取和加载资源方式详解
- 工程目录中文件加载方式
- 解决Unity 中WWW加载 AssetBundle---中文路径
- 解决Unity 中WWW加载 AssetBundle---中文路径
- Unity 截屏,WWW加载图片,保存到本地
- unity用www加载图片出现一个问号。
- 不同方式下文件读取和存储的比较(OpenCV 中FileStorage与C++中文件流ofstream/ifsteam比较)
- unity www缓存图片
- sql优化中遇到的问题
- Java中ArrayList类的用法
- Java synchronized详解
- Windows via C/C++:线程的执行时间(1)
- ViewPager 两边显示部分其他页
- Unity中文件流和WWW的方式加载图片
- liferay6.2通过事件机制实现不同portlet之间数据传递
- 2017年伊始,你需要尝试的25个Android第三方库
- 合并Shader系列 | 如何合并渲染状态
- linux中lost+found目录的作用
- Git学习文档之一 学习文档-发布
- 如何使文字垂直居中
- 文件IO
- activity 章节