Reputation: 13614
I need to crop sub-part from image.
For example,I have this image:
I need to crop the part of the image that in the red frame, I have four coordinates of the frame corners,
Any idea how to implement it?
Thank you in advance.
Upvotes: 0
Views: 373
Reputation:
You can use Graphics.DrawImage();
Rectangle cropRect = new Rectangle(...);
Bitmap src = Image.FromFile(fileName) as Bitmap;
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);
using(Graphics g = Graphics.FromImage(target))
{
g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel);
}
And if need, you can save target to a new file.
Also See : C# Tutorial - Image Editing: Saving, Cropping, and Resizing
Upvotes: 1