C++ Unmanaged array to BitmapData; memcpy?

bwells

Well-known member
Joined
Feb 25, 2003
Messages
84
I see I can use the BitmapData associated with a Bitmap to modify the data of a bitmap. I have constructed a Bitmap of the correct size, and I have an array of byte data which is organized correctly for the Bitmap I want to create.

Since I am working in C++, if I use the scan0 returned from the BitmapData, can I use memcpy to transfer my image data into the bitmap? The scan0 field of the BitmapData returns an IntPtr. Can I use memcpy with an IntPtr to copy my unmanaged data into the bitmap?

thanks
Bryan
 
If you would use GdipCreateBitmapFromScan0 or the bitmap constructor that wraps it: public Bitmap ( System.Int32 width , System.Int32 height , System.Int32 stride , System.Drawing.Imaging.PixelFormat format , System.IntPtr scan0 ) you could just have Scan0 point to the data and create the bitmap from that data all at once, no copying.

After the bitmap has been created, you can LockBits and use Scan0 to alter its pixels, then UnlockBits when done.
 
Back
Top