Capturing a perticular part of an Image
-
I have an Image. I wanted a perticular part of that image of know dimensions that is the Rectangle is know. Can some one tell me how to get this perticular part of the Image. Cheers
-
I have an Image. I wanted a perticular part of that image of know dimensions that is the Rectangle is know. Can some one tell me how to get this perticular part of the Image. Cheers
I am new to C# and .net so there may be a more elegant solution , but the you could do it is as follows; // assume IA is a rectangle that defines the area // of the image you want to crop to and the original // image is in origImage......... Bitmap bmp_cropped = new Bitmap(IA.width, IA.height); Graphics g = Graphics.FromImage(bmp_cropped); g.DrawImage(origImage, 0, 0, IA, GraphicsUnit.Pixel); Hope this is of use. Barry
-
I am new to C# and .net so there may be a more elegant solution , but the you could do it is as follows; // assume IA is a rectangle that defines the area // of the image you want to crop to and the original // image is in origImage......... Bitmap bmp_cropped = new Bitmap(IA.width, IA.height); Graphics g = Graphics.FromImage(bmp_cropped); g.DrawImage(origImage, 0, 0, IA, GraphicsUnit.Pixel); Hope this is of use. Barry
You can also use Bitmap.Clone. It lay you specify a rectangle, which is the part of the image. With Clone, the resulting image will keep the PixelFormat of the source. For instance, if your first image is 8 bits per pixel, indexed, the cloned image will be also. If you use the other method, with DrawImage, the image must be at least 16bpp I think.