title: getting images from web link and converting it into base64string in a loop
body: <p>i need to convert the images(fetching from web service) into base64String to store them in the SQLite database.</p>
  
  <p>EDIT: I use ImageOpened so that the image is loaded/downloaded before I convert them into base64String but ImageOpened doest run. How do I achieve this task ? I mean to convert array of images into base64.</p>
  
  <p>this is my code:</p>
  
  <pre><code>public async void LoadData()
      {
         //get Json
         string str = await Helper.getJSON(); 
  
         //Deserialize json
         MainClass apiData = JsonConvert.DeserializeObject&lt;MainClass&gt;(str);
  
         //the problem loop
         for (int i = 0; i &lt; apiData.Categories.Count;i++ ) 
         {
             //apiData.Categoriesp[i].icon_image is the url of the image
             BitmapImage image = new BitmapImage(new Uri(apiData.Categories[i].icon_image,UriKind.RelativeOrAbsolute));
  
  
           //it never runs
             image.ImageOpened += (s, e) =&gt;
             {
               //code for conversion of image into memory stream
                 image.CreateOptions = BitmapCreateOptions.None;
                 WriteableBitmap wb = new WriteableBitmap(image);
                 MemoryStream ms = new MemoryStream();
                 wb.SaveJpeg(ms, image.PixelWidth, image.PixelHeight, 0, 100);
                 byte[] imageBytes = ms.ToArray();  
  
                 string base64String = Convert.ToBase64String(imageBytes);
  
               //setting imageInSql property of the list (but it never runs)
                 apiData.Categories[i].imageInSql = base64String;
             }; 
  
         } 
  
          //Inserting into database
          using(var db= new SQLiteConnection(App.dbPath)){
                  //geting null in imageinSql property.
                  db.InsertAll(apiData.Categories,typeof(Category));  
          } 
      } 
  </code></pre>
  
  <p>Thanks in advance.</p>