我在使用 C# 的 winform 中有 1 个图片框,我想裁剪图像的某些部分并将所选部分保存到图像中。以下是我用于裁剪源图像的代码
private void picFace_mousedown(object sender, MouseEventArgs e)
{
rect = new System.Drawing.Rectangle(e.X, e.Y, 0, 0);
this.picFace.Invalidate();
}
private void picFace_mousemove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
rect = new System.Drawing.Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
}
this.picFace.Invalidate();
}
private void picFace_paint(object sender, PaintEventArgs e)
{
using (System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
}