I'm trying to crop and resize an image in PictureBox1. My code:
//original image for eventually undo
undoImage = pictureBox1.BackgroundImage.Clone() as Image;
Bitmap sourceBitmap = new Bitmap(pictureBox1.BackgroundImage, pictureBox1.Width, pictureBox1.Height);
Graphics g = pictureBox2.CreateGraphics();
g.DrawImage(sourceBitmap, new Rectangle(0, 0, pictureBox2.Width, pictureBox2.Height), rectCropArea, GraphicsUnit.Pixel);
sourceBitmap.Dispose();
And it working properly on two PictureBox
es.
But PictureBox2.Image
,PictureBox2.BackgroundImage
(and any other including ErrorImage...) = null
.
I tried PictureBox.DrawToBitmap
, and other, like g.GetHdc()
found on google, but unsuccessful.
My question:
How do I properly copy the edited image from PictureBox2
to PictureBox1
?