/* * 加载图片 */ private void LoadImage() { string imageUrl = this.model.imageUrl; if (string.IsNullOrEmpty(imageUrl)) { LogUtils.LogError(this.gameObject.name + " image url is null!"); return; } if (imageUrl.StartsWith("poster")) { LogUtils.Log(this.model.title + " load image from <poster>"); image.texture = Resources.Load(imageUrl) as Texture; } else if (imageUrl.StartsWith("sdcard")) { LogUtils.Log(this.model.title + " load image from <sdcard>"); new LocalImageLoader(imageUrl, true, OnLocalTextureCallback).StartLoad(); } else { string imageLocalPath = LauncherUtils.GetImageCachePath() + GetImageUrl().GetHashCode(); if (!File.Exists(imageLocalPath)) { LogUtils.Log(this.model.title + " load image from <network>"); ImageUtils.Instance.LoadTexture(GetImageUrl()); } else { LogUtils.Log(this.model.title + " load image from <cache>"); new LocalImageLoader(imageLocalPath, true, OnLocalTextureCallback).StartLoad(); } } }
private void SaveToLocal(string imageUrl, HTTPResponse response) { string imagePath = LauncherUtils.GetImageCachePath() + imageUrl.GetHashCode(); if (!File.Exists(imagePath)) { ThreadStart threadStart = new ThreadStart(delegate(){ if (!Directory.Exists(LauncherUtils.GetImageCachePath())) { Directory.CreateDirectory(LauncherUtils.GetImageCachePath()); } Texture2D image = response.DataAsTexture2D; byte[] pngData = image.EncodeToPNG(); File.WriteAllBytes(imagePath, pngData); }); new Thread(threadStart).Start(); } }