title: Create CImage from Byte array
body: <p>I need to create a <a href="http://msdn.microsoft.com/en-us/library/bwea7by5%28v=VS.80%29.aspx" rel="nofollow">CImage</a> from a byte array (actually, its an array of <code>unsigned char</code>, but I can cast to whatever form is necessary). The byte array is in the form "RGBRGBRGB...". The new image needs to contain a <strong>copy</strong> of the image bytes, rather than using the memory of the byte array itself.</p>
  
  <p>I have tried many different ways of achieving this -- including going through various HBITMAP creation functions, trying to use BitBlt -- and nothing so far has worked.</p>
  
  <p>To test whether the function works, it should pass this test:</p>
  
  <pre><code>BYTE* imgBits;
  int width;
  int height;
  int Bpp;   // BYTES per pixel (e.g. 3)
  getImage(&amp;imgBits, &amp;width, &amp;height, &amp;Bpp); // get the image bits
  
  // This is the magic function I need!!!
  CImage img = createCImage(imgBits, width, height, Bpp);
  
  // Test the image
  BYTE* data = img.GetBits();  // data should now have the same data as imgBits
  </code></pre>
  
  <p>All implementations of <code>createCImage()</code> so far have ended up with <code>data</code> pointing to an empty (zero filled) array.</p>