title: How to convert RednerTargetBitmap image into byteArray for uploading on server in UWP
body: <p>I have a grid that covers whole screen and i want to make that grid as image and then this image i want to send on server. I have used RenderTargetBitmap for this purpose and successfully make writeablebitmap to save using FileSave Picker. Image save is at normal size as expected 700kb but these bytes are too big for uploading on server. Expected bytes for 700kb image could be 200 thousand but in my situation bytes are more than 30 hundred thousand. There is definitely issue with bytes.
  Here is code that i use to save grid as image using file save picker.</p>
  
  <pre><code>        await bitmap.RenderAsync(testgrid);
          var pixelBuffer = await bitmap.GetPixelsAsync();
          byte[] pixels = pixelBuffer.ToArray();
          var wb = new WriteableBitmap((int)bitmap.PixelWidth, (int)bitmap.PixelHeight);
          using (stream2 = wb.PixelBuffer.AsStream())
          {
              await stream2.WriteAsync(pixels, 0, pixels.Length);            
          }
          FileSavePicker picker = new FileSavePicker();
  
          picker.FileTypeChoices.Add("JPG File", new List&lt;string&gt;() { ".jpg" });
  
          StorageFile file = await picker.PickSaveFileAsync();
          if (file != null)
          {
              await (wb as WriteableBitmap).SaveAsync(file);
          }   
  </code></pre>
  
  <p>The above code successfully save image to given location with normal size.
  but when i use above pixel byte array to server. Http send task cancelled exception while send request and i have detail checked on it. It is due to huge amount of Bytes array.
  Also if i send a very small grid of 50x50 then uploading done successfully because it has 30 thousand bytes only but image uploaded on the server is empty or corrupted. </p>
  
  <p>Also i have used above converted writeablebitmap to make its bytes array using this method...</p>
  
  <pre><code>using (Stream stream = mywriteablebitmap.PixelBuffer.AsStream())
          using (MemoryStream memoryStream = new MemoryStream())
          {
              stream.CopyTo(memoryStream);
              return memoryStream.ToArray();
          }
  </code></pre>
  
  <p>it also returns same number of bytes Array and same error occurred from server.</p>
  
  <p>Please tell me the correct way of making byte array from RenderTargetBitmap and that can easily be uploaded on server.</p>