简体   繁体   中英

picturebox1.Image = bmp VS picturebox1.Image = new Bitmap(bmp)?

I use the common way to draw on a picturebox, that is drawing on a bitmap first and after copying it's content to the picturebox image.

Bitmap bmp;
bmp = new Bitmap(pb.Width, pb.Height);

Graphics g = Graphics.FromImage(bmp);
g.Draw(...);

I was wondering that after dowing all the drawing staff is there any difference between using the followings?

pb.Image = bmp;

or

pb.Image = new Bitmap(bmp);

Yes there is pb.Image = bmp; Assigns the existing bitmap to your property. pb.Image = new Bitmap(bmp); Creates a new bitmap, it's essentially a deep copy.

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