Example #1
0
 public void DownloadImage(string url, OnImageLoaded onImageLoaded, OnDownloadProgress onDownloadProgress)
 {
     //if (coWebReq != null)
     //    StopCoroutine(coWebReq);
     //coWebReq =
     StartCoroutine(RequestPicture(url, 60f, onImageLoaded, onDownloadProgress));
 }
Example #2
0
 public static void BeginDownloadImageFromUrl(string url, Action <FileLoadedArgs> downloadImageFromUrlCompleted = null)
 {
     Task.Run(async() =>
     {
         UIImage currentImage = await ImageService.Instance.LoadUrl(url).AsUIImageAsync();
         OnImageLoaded?.Invoke(new Object(), new FileLoadedArgs(url, currentImage));
         downloadImageFromUrlCompleted?.Invoke(new FileLoadedArgs(url, currentImage));
     });
 }
Example #3
0
    IEnumerator LoadImage_I(string url, OnImageLoaded onImageLoaded)
    {
        WWW www = new WWW(url);

        yield return(www);

        if (www.error == null)
        {
            Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
            www.LoadImageIntoTexture(texture);
            onImageLoaded(texture);
        }
        else
        {
            onImageLoaded(null);
        }
        www.Dispose();
    }
Example #4
0
 private void loadHiRes()
 {
     if (img == null)
     {
         BitmapImage bmp = new BitmapImage();
         bmp.BeginInit();
         bmp.CacheOption = BitmapCacheOption.OnLoad;
         bmp.UriSource   = new Uri(toLoad);
         bmp.EndInit();
         bmp.Freeze();
         OnImageLoaded.Invoke(bmp);
     }
     else
     {
         BitmapImage b = img.GetImage();
         b.Freeze();
         OnImageLoaded.Invoke(b);
     }
 }
Example #5
0
        public delegate void OnImageLoadError(string code); // Image Loading Error

        public IEnumerator LoadImage(string url, Image image, OnImageLoaded complete = null, OnImageLoadError error = null)
        {
            url = url.Replace(@"\", ""); // Replace Wrong Slashes
            var request = new WWW(url);  // Create WWW Request

            yield return(request);       // Send Request

            // Work with Response
            if (request.error != null)                                                                                        // Request has error
            {
                error("Не удалось загрузить изображение. Пожалуйста, проверьте соединение с интернетом и попробуйте снова."); // Do error
            }
            else                                                                                                              // No Errors
            {
                image.sprite = Sprite.Create(request.texture, new Rect(0, 0, request.texture.width, request.texture.height), new Vector2(0, 0));
                if (complete != null)
                {
                    complete();
                }
            }
        }
Example #6
0
    IEnumerator RequestPicture(string url, float timeOut, OnImageLoaded onImageLoaded, OnDownloadProgress onDownloadProgress)
    {
        UnityWebRequest webRequest            = UnityWebRequestTexture.GetTexture(url);
        UnityWebRequestAsyncOperation handler = webRequest.SendWebRequest();

        float timeIn    = 0f;
        bool  isAborted = false;

        while (!handler.isDone)
        {
            timeIn += Time.deltaTime;
            if (onDownloadProgress != null)
            {
                onDownloadProgress(handler.progress);
            }
            if (timeIn > timeOut)
            {
                //Security
                isAborted = true;
                webRequest.Abort();
                break;
            }
            yield return(null);
        }

        if (webRequest.isNetworkError || webRequest.isHttpError || isAborted)
        {
            Debug.Log(webRequest.error);
            onImageLoaded(null);
        }
        else
        {
            //Call end
            Texture2D textureRequested = DownloadHandlerTexture.GetContent(webRequest);
            onImageLoaded(textureRequested);
        }

        yield break;
    }
Example #7
0
 public void LoadImage(string url, OnImageLoaded onImageLoaded)
 {
     StartCoroutine(LoadImage_I(url, onImageLoaded));
 }