title: How create Managed.Graphics.Direct2D.Bitmap object from byte array c#
body: <p>I am traying to make video player. I want draw images with sharpdx sdk because of cpu isue. But I have an isue. I am getting frames as byte array. Pixel format of images are BGRA32. I wrote following code to convert it. But it gives to me error "Value does not fall within the expected range".</p>
  
  <p>My code is : </p>
  
  <pre><code>private Bitmap getBitmap(byte[] frame) {
     return RenderTarget.CreateBitmap(new SizeU((uint)img_w, (uint)img_h), frame, 0, new BitmapProperties(new PixelFormat(DxgiFormat.B8G8R8A8_UNORM, AlphaMode.Ignore), 100, 100));
  }
  </code></pre>
  
  <p>Note : img_w = 720, img_h = 576, length of frame array = 720 * 576 * 4</p>
  
  <p>I tried that first of all create image than copy data to image. But it doesn't work also. It copies first row to all row. <a href="https://i.stack.imgur.com/B15P0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B15P0.jpg" alt="enter image description here"></a></p>
  
  <p>Left image is original image, right is created by copy from byte array . I used following code to create this image.</p>
  
  <pre><code>private Bitmap getBitmap(byte[] frame) {
          var bmp = RenderTarget.CreateBitmap(new SizeU((uint)img_w, (uint)img_h), IntPtr.Zero, 0, new BitmapProperties(new PixelFormat(DxgiFormat.B8G8R8A8_UNORM, AlphaMode.Ignore), 100, 100));
          bmp.CopyFromMemory(new RectU(0, 0, (uint)img_w, (uint)img_h), frame, 0);
  
          return bmp;
      }
  </code></pre>