3
votes

Can you combine the methods of Bitmap.LockBits and Graphics.FromImage, or in other words if I have a bitmap "bmp" and I want to edit the bitmap with a Graphics-object g, are the changes visible in the byte-array of the BitmapData.Scan0:

Bitmap bmp = new Bitmap(200,200);
Graphics g = Graphics.FromImage(bmp);
bmp.LockBits(new Rectangle(0,0,200,200),
    ImageLockMode.ReadOnly,PixelFormat.Format32bppArgb);
byte* pixelData = (byte*) (void*) bmd.Scan0;
g.FillRectangle(Brushes.Red,new Rectangle(0,0,50,50));

can I see the changes in PixelData after I filled a red rectangle?

1

1 Answers

2
votes

Yes should be able to combine operations if the operations don't use the same type of locking, meaning that you should pass a compatible ImageLockMode parameter to your LockBits method.