我正在制作一个裁剪图像的程序.我有两个PictureBoxes和一个名为'crop'的按钮.一个图片框包含一个图像,当我在其中选择一个矩形并按"裁剪"时,所选区域出现在另一个图片框中; 所以当我按下裁剪时程序正在运行.问题是:如何将裁剪区域的图像转换为图片框?
Rectangle rectCropArea;
Image srcImage = null;
TargetPicBox.Refresh();
//Prepare a new Bitmap on which the cropped image will be drawn
Bitmap sourceBitmap = new Bitmap(SrcPicBox.Image, SrcPicBox.Width, SrcPicBox.Height);
Graphics g = TargetPicBox.CreateGraphics();
g.DrawImage(sourceBitmap, new Rectangle(0, 0, TargetPicBox.Width, TargetPicBox.Height),
rectCropArea, GraphicsUnit.Pixel);
//Good practice to dispose the System.Drawing objects when not in use.
sourceBitmap.Dispose();
Image x = TargetPicBox.Image;
Run Code Online (Sandbox Code Playgroud)
问题是x = null并且图像显示在图片框中,那么如何将图像从此图片框中转换为Image变量?