title: ID2D1Bitmap1::Map, when can you use it?
body: <p>So I recently went through and converted a simple test app I wrote to use the new version of Direct2D, which means I basically copied the relevant parts of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh780340%28v=vs.85%29.aspx" rel="nofollow">the Direct2D Quickstart for Windows 8</a>.  That worked, in that my application behaved as before (just draws a bunch of pixels.)</p>
  
  <p>Previously, to update the bitmap, I was doing the following:</p>
  
  <pre><code>for(int i = 0; i &lt; 1000; ++i )
  {
      int x = rand()%600;
      int y = rand()%600;
      int index = 4 * ( x + ( y * 600 ) );
      imageData[index] = rand()%256;
      imageData[index+2] = 0;
  }
  
  D2D1_RECT_U rect2 = RectU(0,0,600,600);
  pBitmap-&gt;CopyFromMemory(&amp;rect2, imageData, 600*4);
  </code></pre>
  
  <p>where imageData is just:</p>
  
  <pre><code>imageData = new byte[600*600*4];
  </code></pre>
  
  <p>That still worked, but I thought that since I've got this nifty Map method on my shiny new ID2D1Bitmap1 interface that I could get rid of that CPU-side array and do something like:</p>
  
  <pre><code>D2D1_MAPPED_RECT* mapped = NULL;
  ThrowIfFailed( pBitmap-&gt;Map( D2D1_MAP_OPTIONS_WRITE, mapped ) );
  
  for(int i = 0; i &lt; 1000; ++i)
  {
      int x = rand()%600;
      int y = rand()%600;
      int index = 4 * ( x + ( y * 600 ) );
      mapped-&gt;bits[index] = rand()%256;
      mapped-&gt;bits[index+2] = 0;
  }
  
  ThrowIfFailed(pBitmap-&gt;Unmap());
  </code></pre>
  
  <p>This failed at the call to Map with E_INVALIDARG, every time, using various combinations of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh446984%28v=vs.85%29.aspx" rel="nofollow">D2D1_BITMAP_OPTIONS</a> in the D2D1_BITMAP_PROPERTIES1 passed to CreateBitmap and <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh447006%28v=vs.85%29.aspx" rel="nofollow">D2D1_MAP_OPTIONS</a> in the call to Map.</p>
  
  <p>Looking at the description of the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh447006%28v=vs.85%29.aspx" rel="nofollow">D2D1_MAP_OPTIONS enumeration</a> it appears that none of the 3 options (READ, WRITE, DISCARD) can actually be used on bitmaps I create with the Direct2D context...  </p>
  
  <p>How do I get, in Direct2D, a bitmap which I can map, write to, unmap and draw?</p>