There is a loaded image (placed in the picturebox or simply as an Image object in memory). Its dimensions are known (let it be 1000 by 2000). It is necessary to cut it, for example, to 500 per 1000 (just cut, without any selection of the area. Cut a piece, starting from the upper left corner).

Tell me, please, how it is done. Many googled, read msdn , but did not find a clear solution.

Help with examples, who than can!

Thanks in advance!

    2 answers 2

    Cropping Images , if the code is working, then I think you will understand

     public static Image Crop(this Image image, Rectangle selection) { Bitmap bmp = image as Bitmap; // Check if it is a bitmap: if (bmp == null) throw new ArgumentException("No valid bitmap"); // Crop the image: Bitmap cropBmp = bmp.Clone(selection, bmp.PixelFormat); // Release the resources: image.Dispose(); return cropBmp; } 


     Image.Crop(new Rectangle(0, 0, 500, 1000)); 
    • Thank you - Jembo_by 9:04 pm

    the method is good, but use it simply as image.Crop(new Rectangle(0, 0, twp, thp)); no, because the result will not be written to the current instance. This is how it works:

     image = image.Crop(new Rectangle(0, 0, twp, thp));