Guest User

DownloadingImage

a guest
Feb 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1.   void DownloadImage()
  2.     {
  3.         using (var webClient = new WebClient())
  4.         {
  5.  
  6.             webClient.DownloadDataCompleted += WebClient_DownloadDataCompleted;
  7.             var imageBytes = webClient.DownloadDataTaskAsync(imageURL);
  8.             downloadStarted = true;
  9.  
  10.         }
  11.     }
  12.     void WebClient_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e)
  13.     {
  14.         Debug.Log(sender.ToString());
  15.         var imageBytes = e.Result;
  16.  
  17.         if (imageBytes != null && imageBytes.Length > 0)
  18.         {
  19.             var texture = new Texture2D(2, 2);
  20.             texture.LoadImage(imageBytes);
  21.             Rect rec = new Rect(0, 0, texture.width, texture.height);
  22.             var spriteToUse = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);
  23.         }
  24.     }
Add Comment
Please, Sign In to add comment