【发布时间】:2015-07-11 02:26:39
【问题描述】:
我正在制作一个裁剪图像的程序。我有两个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;
问题是 x = null 并且图像显示在图片框中,那么我怎样才能从这个图片框中获取图像到 Image 变量中?
【问题讨论】:
标签: c# winforms system.drawing