Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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 it's pixels, then UnlockBits when done.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...