title: Is there a fast alternative to creating a Texture2D from a Bitmap object in XNA?
body: <p>I've looked around a lot and the only methods I've found for creating a Texture2D from a Bitmap are:</p>
  
  <pre><code>using  (MemoryStream s = new  MemoryStream())
  {
     bmp.Save(s, System.Drawing.Imaging.ImageFormat.Png);
     s.Seek(0, SeekOrigin.Begin);
     Texture2D tx = Texture2D.FromFile(device, s);
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Texture2D tx = new Texture2D(device, bmp.Width, bmp.Height,
                          0, TextureUsage.None, SurfaceFormat.Color);
  tx.SetData&lt;byte&gt;(rgbValues, 0, rgbValues.Length, SetDataOptions.NoOverwrite);
  </code></pre>
  
  <p>Where rgbValues is a byte array containing the bitmap's pixel data in 32-bit ARGB format.</p>
  
  <p>My question is, are there any faster approaches that I can try?</p>
  
  <p>I am writing a map editor which has to read in custom-format images (map tiles) and convert them into Texture2D textures to display.  The previous version of the editor, which was a C++ implementation, converted the images first into bitmaps and then into textures to be drawn using DirectX.  I have attempted the same approach here, however both of the above approaches are significantly too slow.  To load into memory all of the textures required for a map takes for the first approach ~250 seconds and for the second approach ~110 seconds on a reasonable spec computer (for comparison, C++ code took approximately 5 seconds).  If there is a method to edit the data of a texture directly (such as with the Bitmap class's LockBits method) then I would be able to convert the custom-format images straight into a Texture2D and hopefully save processing time.</p>
  
  <p>Any help would be very much appreciated.</p>
  
  <p>Thanks</p>