title: Image is not converted from Uri to Bitmap image in UWP
body: <p>I have referred the below thread for combing multiple images as single image in uwp.
  <a href="https://stackoverflow.com/questions/23655074/merging-multiple-images">Merging multiple Images</a></p>
  
  <p>But the image is not properly converted from Uri to bitmap images for the tiles downloaded from below link</p>
  
  <p><a href="https://a.tile.openstreetmap.org/0/0/0.png" rel="nofollow noreferrer">https://a.tile.openstreetmap.org/0/0/0.png</a></p>
  
  <pre><code>  public MainPage()
          {
              this.InitializeComponent();
              MergeImages();
          }
  
          async void MergeImages()
          {
              byte[] Canvas = new byte[512 * 512 * 4];
  
                  Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(
                      new Uri("https://a.tile.openstreetmap.org/1/0/0.png",UriKind.RelativeOrAbsolute)).OpenReadAsync();
                  Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);
                  Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
                  byte[] tileImage = pixelData.DetachPixelData();
                  Canvas = PutOnCanvas(Canvas, tileImage, 0,
                      0, 256, 256, 512);
  
              InMemoryRandomAccessStream memStream = new InMemoryRandomAccessStream();
              var encoder = await BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, memStream);
              encoder.SetPixelData(
                  Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8,
                  Windows.Graphics.Imaging.BitmapAlphaMode.Straight,
                 512, // pixel width
                 512, // pixel height
                  96, // horizontal DPI
                  96, // vertical DPI
                  Canvas);
  
              try
              {
                  await encoder.FlushAsync();
                  var bitmapImage = new BitmapImage();
  
                  await bitmapImage.SetSourceAsync(memStream);
                  image.Source = bitmapImage;
              }
              catch { }
              memStream.Dispose();
          }
  
          byte[] PutOnCanvas(byte[] Canvas, byte[] Image, uint x, uint y, uint imageheight, uint imagewidth, uint CanvasWidth)
          {
              for (uint row = y; row &lt; y + imageheight; row++)
                  for (uint col = x; col &lt; x + imagewidth; col++)
                      for (int i = 0; i &lt; 4; i++)
                          Canvas[(row * CanvasWidth + col) * 4 + i] = Image[((row - y) * imagewidth + (col - x)) * 4 + i];
  
              return Canvas;
          }
  </code></pre>
  
  <p><a href="http://www.syncfusion.com/downloads/support/directtrac/general/ze/BitmapConversio1484632127" rel="nofollow noreferrer">Sample</a></p>
  
  <p><a href="https://i.stack.imgur.com/jxmAu.png" rel="nofollow noreferrer">Actual Output:</a></p>
  
  <p><a href="https://i.stack.imgur.com/Z5crf.png" rel="nofollow noreferrer">Expected output</a></p>