I'm trying work with BitmapData class? and have some problems with assigning IntPtr value to the BitmapData.Scan0 property. Here is my code:
var data = bmp.LockBits(new rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
data.Scan0 = rh.data.Scan0HGlobal;
bmp.UnlockBits(data);
But, after unlocking image, it doesn't changes. Why? In debugging mode i saw that data.Scan0 was changed to the rh.data.Scan0HGlobal value. In rh.data.Scan0HGlobal i have pointer to the memory where contains raw data of pixels.
Well, it's a bit sad that Scan0 property setter is not private. But yes, this doesn't do anything. You'll need to copy the bytes yourself to alter the image. Use Marshal.Copy() to copy through a byte[] helper array of pinvoke memcpy().