   From: Quick code to get a WPF Visual to DirectX Texture (performance wise)
  I tried to load the data using CopyPixels(), but it throws D3DXERR_INVALIDDATA exception.RenderTargetBitmap bmp = GetBitmap();// copy into a byte arrayint stride = bmp.PixelWidth * 4; byte[] data = new byte[bmp.PixelHeight * stride]; bmp.CopyPixels(data, stride, 0); // create textureusing (MemoryStream ms = new MemoryStream(data)){    ms.Seek(0, SeekOrigin.Begin);    if (dxDevice != null)    {   // next line throws D3DXERR_INVALIDDATA exception   texture = TextureLoader.FromStream(dxDevice, ms);    }}