title: WPF download image bytes from Blob Storage
body: <p>I want to preload a lot of images when my app starts up, sort of a once off thing.</p>
  
  <p>I have an <code>Image</code> class that contains the Url of its image stored in the cloud as blob storage (this address is a <strong>https</strong> address BTW)</p>
  
  <p>I want to download the image bytes from the cloud, store them on the object, then when it comes time to show the image, load the image from its bytes.</p>
  
  <p>I have all the code for this, but I keep getting the exception: </p>
  
  <p><strong>No imaging component suitable to complete this operation was found.</strong></p>
  
  <p>Here is my code: <strong>EDIT UPDATED WITH A FIX</strong></p>
  
  <pre><code>    //Loaded on start-up
      private static void LoadImageBytes(Image img)
      {
          var urlUri = new Uri(img.Url);
          var request = (HttpWebRequest)WebRequest.CreateDefault(urlUri);
          MemoryStream memStream = new MemoryStream();
  
          using (var response = request.GetResponse())
          {
              var buffer = new byte[4096];
              using (var stream = response.GetResponseStream())
              {
                  int bytesRead = stream.Read(buffer, 0, buffer.Length);
                  while (bytesRead &gt; 0)
                  {
                      memStream.Write(buffer, 0, bytesRead);
                      bytesRead = stream.Read(buffer, 0, buffer.Length);
                  }
  
                  img.ImageBytes = memStream.ToArray();
              }
          }
      }
  </code></pre>
  
  <p>Then when I want to get the image on the screen I call this:</p>
  
  <pre><code>    public BitmapImage ImageFromBuffer(Byte[] bytes)
      {
          MemoryStream stream = new MemoryStream(bytes);
          stream.Seek(0, SeekOrigin.Begin);
          BitmapImage image = new BitmapImage();
          image.BeginInit();
          image.StreamSource = stream;
          image.EndInit();
          return image;
      }
  </code></pre>
  
  <p>But in the <strong>EndInit()</strong> call I get the exception.</p>
  
  <p>I have done some testing and if I load the file from my local filesystem, I get a different set of bytes to that of the image in the cloud. I assume its something to do with blob storage or https?</p>
  
  <p><em>And yes I can browse to that image and its not corrupted.</em></p>
  
  <p><strong>EDIT, fixed now all good</strong></p>