简体   繁体   中英

Are Bitmap.LockBits and Graphics.FromImage combinable in C#

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?

如果操作不使用相同类型的锁定,则应该能够组合操作,这意味着您应该将兼容的ImageLockMode参数传递给LockBits方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM