picturebox1中打开了一副图像,现在的话,在picturebox1中选取了两个点(x0,y0)以及(x1,y1)。如何在picturebox2中绘制坐标x0~x2,y0~y1这部分的图像?代码的话又该怎么写呢?
那么如何将改部分的图像在picturebox2中显示呢?下面代码的在运行时会报错,错误为:pictureBox2.Image =
bmSmall;这一句
未将对象引用设置到对象的实例。
Rectangle rect = new Rectangle(x0,y0,(x1-x0),(y1-y0));
Bitmap bmSmall = new Bitmap(rect.Width, rect.Height,
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
using
(Graphics grSmall = Graphics.FromImage(bmSmall))
{
grSmall.DrawImage(pictureBox1.Image, new
System.Drawing.Rectangle(0, 0, bmSmall.Width, bmSmall.Height), rect,
GraphicsUnit.Pixel);
grSmall.Dispose();
pictureBox2.Image =
bmSmall;
}
那么如何将改部分的图像在picturebox2中显示呢?追问中无法写了,我写在补充问题里了,麻烦你看一下
追答AcquireRectangleImage函数返回的是一个Image对象
直接
picturebox2.image = AcquireRectangleImage就可以了。
具体自己试一下。