Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract sub image from an Image using c#

Tags:

c#

image

I have a Bitmap object from this I need to extract a sub image and keep it as a Bitmap object by passing Rectangle object which contains sub image co-ordinates?

Is there a c# library which is able to do this or is Aforge able to extract sub image.

Thanks

like image 406
kumar Avatar asked Jul 12 '12 17:07

kumar


1 Answers

The Bitmap class has a Clone method which accepts a target rectangle directly.

Since you're already working with a Bitmap, calling Clone with your rectangle and desired PixelFormat (which could be originalBitmap.PixelFormat) should give you what you need, with no additional dependencies.

Bitmap croppedImage = originalBitmap.Clone(theRect, originalBitmap.PixelFormat);
like image 65
Reed Copsey Avatar answered Sep 19 '22 12:09

Reed Copsey