title: Xamarin.Forms: How to load an image from Resources into a byte-array?
body: <p>I have a (hopefully) simple question (I don’t have found an answer, that fit’s by all of my searches).</p>
  
  <p>I work with Xamarin.Forms 1.4.1-Pre-1.
  In my app, I have:</p>
  
  <pre><code>byte[] AvatarErfassung; // Bytearray, to later update the webservice
  var Avatar = new Image { HeightRequest = 71, WidthRequest = 61, HorizontalOptions = LayoutOptions.Start };
  Avatar.Source = "SymbolMann.jpg";  
  </code></pre>
  
  <p>where the image "SymbolMann.jpg” <strong>is included as project-resource</strong> (in each project) and showed on a page (without problems).<br>
  I now want to put the image in a byte-array to send it to our webservice.
  I don't have found any way to access the image "SymbolMann.jpg" (to load it in a byte-array) or to use (however) the Avatar.Source therefore.</p>
  
  <p><strong>Question:</strong><br>
  <strong>How to get the image “SymbolMann.jpg” into the byte-array “AvatarErfassung” ?</strong>    </p>
  
  <p><strong>Thanks for every answer</strong></p>
  
  <p>Hi Dimitris</p>
  
  <p>Thanks for your (fast) replay.<br>
  As I wrote, I work with Xamarin.<strong>Forms</strong>.<br>
  The images are stored as <strong>resources</strong>:
  in \Resources\Drawable\ (for Android), \Resources\ (for iOS) and in the root (for WP). 
  I have to load the image on a content-page.</p>
  
  <p>If I overtake your code, to the line:</p>
  
  <pre><code>var assembly = this.GetType().GetTypeInfo().Assembly;
  </code></pre>
  
  <p>I have the error-message (translated to English):<br>
  “System.Type don’t contain a definition for GetTypeInfo method (is a using missing?)”</p>
  
  <p><strong>Do I have to add a specific using?</strong></p>
  
  <p>You write:
  // you can replace "this.GetType()" with "typeof(MyType)", where MyType is any type in your assembly.</p>
  
  <p><strong>What do I have to place as type?</strong></p>
  
  <p><strong>= typeof(????).GetTypeInfo().Assembly:</strong></p>
  
  <p><strong>Thanks for a further reply.</strong></p>
  
  <p>Update #2:</p>
  
  <p>Firts, thanks for your patience…</p>
  
  <p>Unfortunately in <strong>VS2013</strong>, I don’t find any function “resolve” that shows me the missing using - but I have find out the missing using my self :-)<br>
  In the meantime I have added 
  using System.Reflection;</p>
  
  <p>Now, the line:
  var assembly = this.GetType().GetTypeInfo().Assembly;</p>
  
  <p>is resolved and compiled without error</p>
  
  <p>Further, I have changed the type of the .jpg from “Android Resource” to “Embedded Ressource”.<br>
  The App then <strong>crashes</strong> in the line:
  long length = s.Length;
  <strong>as it seems that s is null (I think the jpg is not found)</strong></p>
  
  <p>Further -  if I change the type to “Embedded Ressource” - <strong>the image is not found any more by Xamarin.Forms (Avatar.Source = "SymbolMann.jpg";)</strong>  </p>
  
  <p>If I change the type of the .jpg to “Compile” I can’t compile the app.<br>
  Error-message:
  A namespace can’t contain directly members like fields or methods.</p>
  
  <p><strong>So… what is the correct type to the resource (so that it can be loaded with assembly.GetManifestResourceStream()?</strong></p>
  
  <p><strong>Do I have to add something to the filename (SymbolMann.jpg) so that it will be found?</strong>  </p>
  
  <p><strong>How do I have to change Avatar.Source = "SymbolMann.jpg" so that it is found (if I change the type from “Android Resource” to anything else)?</strong></p>
  
  <p>Once again my needs:<br>
  On a registration-page, default-images (symbols) are showed as avatar for man and woman in a standard-Xamarin.Forms image (avatar.source = “SymbolMann.jpg” / “SymbolFrau.jpg”).<br>
  The .jpg’s are stored in the standard-directories for each project (Android, iOS and WP) where the are accessible without problems from the image-object.<br>
  The user then can take one of the default-images or load another one over mediapicker.<br>
  If the user the tap the button “Register”, I have to create a byte-array from the Image to send it via json to our webservice.<br>
  If the user select another image via mediapicker, I <strong>have</strong> access to the stream, the problem is, to become a byte-array from the default-images (in every platform).</p>
  
  <p>Once again thanks for your help...</p>