title: Xamarin Forms Image to Stream
body: <p>My goal is to take an embedded image which is saved in each project's image folder, stream it, convert it to a byte array and save it to the device's local storage file system using PCLStorage. The part which I cannot figure out is how to stream from the embedded image.</p>
  
  <pre><code>var embeddedImage = new Image { Aspect = Aspect.AspectFit };
  embeddedImage.Source = ImageSource.FromResource("applicationIcon.png");
  </code></pre>
  
  <p>then I could stream it if I had the path, or I could convert it to a <code>byte []</code> if I had a stream. The code below does not work because the file source is not found (obviously). </p>
  
  <pre><code>string localFileUri = string.Empty;
  
  // Get hold of the file system.
  IFolder localFolder = FileSystem.Current.LocalStorage;
  
  IFile file = await FileSystem.Current.GetFileFromPathAsync("applicationIcon.png");
  
  using (Stream stream = await file.OpenAsync(FileAccess.Read))
  {
      using (var ms = new MemoryStream())
      {
          var byteArray = ms.ToArray();
  
          var storeragePath = await iStorageService.SaveBinaryObjectToStorageAsync(string.Format(FileNames.ApplicationIcon, app.ApplicationId), byteArray);
          app.IconURLLocal = storeragePath;
      }
  }
  </code></pre>
  
  <p>The only option seems to be to use some kind of resource locator, and then maintain that code for each type of project you add. Not very elegant. Is there another way?</p>