/// <summary> /// Asynchronously downloads an image from the provided url. /// </summary> /// <param name="url">The URL.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="callback">Callback that will be invoked on the UI thread.</param> public static void GetImageAsync(string url, bool useCache, GetImageCallback callback) { // Cache not to be used ? if (!useCache) { EveClient.HttpWebService.DownloadImageAsync(url, GotImage, callback); return; } // First check whether the image exists in cache. string cacheFileName = Path.Combine(ImageCacheDirectory, GetCacheName(url)); if (File.Exists(cacheFileName)) { try { Image img = Image.FromFile(cacheFileName, true); callback(img); } catch (Exception e) { ExceptionHandler.LogException(e, false); } } // In last resort, downloads it. EveClient.HttpWebService.DownloadImageAsync(url, GotImage, (GetImageCallback)((img) => { if (img != null) AddImageToCache(url, img); callback(img); })); }
IEnumerator GetImageCoroutine(string url, GetImageCallback callback) { WWW www = new WWW(url); yield return(www); Texture2D texture = www.texture; callback(texture); }
/// <summary> /// Callback used when images are downloaded, it takes care to invoke another callback provided as our user state. /// </summary> /// <param name="e"></param> /// <param name="state"></param> private static void GotImage(DownloadImageAsyncResult e, object state) { GetImageCallback callback = (GetImageCallback)state; if (e.Error == null) { // Invokes on the UI thread. Dispatcher.BeginInvoke(() => callback(e.Result)); } else { ExceptionHandler.LogException(e.Error, true); callback(null); } }
/// <summary> /// Asynchronously downloads an image from the provided url. /// </summary> /// <param name="url">The URL.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="callback">Callback that will be invoked on the UI thread.</param> public static void GetImageAsync(string url, bool useCache, GetImageCallback callback) { // Cache not to be used ? if (!useCache) { EveClient.HttpWebService.DownloadImageAsync(url, GotImage, callback); return; } // First check whether the image exists in cache. string cacheFileName = Path.Combine(ImageCacheDirectory, GetCacheName(url)); if (File.Exists(cacheFileName)) { try { Image img = Image.FromFile(cacheFileName, true); callback(img); } catch (Exception e) { ExceptionHandler.LogException(e, false); } } // In last resort, downloads it. EveClient.HttpWebService.DownloadImageAsync(url, GotImage, (GetImageCallback)((img) => { if (img != null) { AddImageToCache(url, img); } callback(img); })); }
public static extern IntPtr Online(string rtsp, GetImageCallback getImageCallback);
/// <summary> /// Asynchronously downloads a character portrait from its ID. /// </summary> /// <param name="charId"></param> /// <param name="callback">Callback that will be invoked on the UI thread.</param> public static void GetCharacterImageAsync(long charId, GetImageCallback callback) { GetImageAsync(String.Format(NetworkConstants.CCPPortraits, charId.ToString()), false, callback); }
public void GetImage(string url, GetImageCallback callback) { Debug.Log("Getting image from: " + url); StartCoroutine(GetImageCoroutine(url, callback)); }