Package COM. yanek. util; import Java. AWT. rectangle; import Java. AWT. image. bufferedimage; import Java. io. file; import Java. io. fileinputstream; import Java. io. ioexception; import Java. util. iterator; import javax. imageIO. imageIO; import javax. imageIO. imagereadparam; import javax. imageIO. imagereader; import javax. imageIO. stream. imageinputstream; public class imgcututil {/*** @ Param ARGs */public static void main (String [] ARGs) {imgcututil. cut (30, 50,300,400, "d:/1.jpg"," d:/100.jpg ");} /*** image cropping ** @ Param X1 select the X coordinate in the upper left corner of the area * @ Param Y1 select the Y coordinate in the upper left corner of the area * @ Param width select the area width * @ Param height select the area * @ Param sourcepath source image path * @ Param descpath: Save the cropped image path */public static void cut (INT X1, int Y1, int width, int height, string sourcepath, string descpath) {fileinputstream is = NULL; imageinputstream IIS = NULL; try {is = New fileinputstream (sourcepath); string filesuffix = sourcepath. substring (sourcepath. lastindexof (". ") + 1); iterator <imagereader> it = ImageIO. getimagereadersbyformatname (filesuffix); imagereader reader = it. next (); IIS = ImageIO. createimageinputstream (is); reader. setinput (IIS, true); imagereadparam Param = reader. getdefaultreadparam (); rectangle rect = new rectangle (x1, Y1, width, height); Param. setsour Ceregion (rect); bufferedimage Bi = reader. read (0, Param); ImageIO. write (Bi, filesuffix, new file (descpath);} catch (exception ex) {ex. printstacktrace ();} finally {If (is! = NULL) {try {is. Close () ;}catch (ioexception e) {e. printstacktrace () ;}is = NULL ;}if (IIS! = NULL) {try {IIS. Close () ;}catch (ioexception e) {e. printstacktrace () ;}iis = NULL ;}}}}