i am having 1 picturebox in winform using C#, i want to crop some part of image and save that selected part it into image. Following is my code for croping source image
我正在使用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);
}
}
1 个解决方案
#1
1
Simple, Bitmap has a clone method takes the rectangle you have defined.
简单,Bitmap有一个克隆方法,它采用你定义的矩形。
http://msdn.microsoft.com/en-us/library/ms141944.aspx
http://msdn.microsoft.com/en-us/library/ms141944.aspx
Then when you have your new bitmap, it comes with a save method
然后,当您有新的位图时,它会带有一个保存方法
http://msdn.microsoft.com/en-us/library/ktx83wah.aspx
http://msdn.microsoft.com/en-us/library/ktx83wah.aspx
#1
1
Simple, Bitmap has a clone method takes the rectangle you have defined.
简单,Bitmap有一个克隆方法,它采用你定义的矩形。
http://msdn.microsoft.com/en-us/library/ms141944.aspx
http://msdn.microsoft.com/en-us/library/ms141944.aspx
Then when you have your new bitmap, it comes with a save method
然后,当您有新的位图时,它会带有一个保存方法
http://msdn.microsoft.com/en-us/library/ktx83wah.aspx
http://msdn.microsoft.com/en-us/library/ktx83wah.aspx