/** <Br/> * crop the image and save the cropped image. <Br/> * @ Param srcpath: full path of the cropped image <br/> * @ Param tarpath: save the complete path of the cropped new image <br/> * @ Param X: the horizontal displacement of the top left vertex of the rectangular area. <br/> * @ Param Y: trim the vertical displacement of the top left vertex of the rectangle area <br/> * @ Param width: trim the width of the rectangle area <br/> * @ Param height: cut the height of the rectangular area <br/> */<br/> Public static void cut (string srcpath, string tarpath, int X, int y, int width, int height) {<br/> try {<br/> // read the image file <br/> fileinputstream is = new fileinputstream (srcpath ); </P> <p> // obtain the image stream <br/> imageinputstream IIS = ImageIO. createimageinputstream (is); </P> <p> // convert to output stream <br/> bufferedimage outputimage = getsubimage (ImageIO. read (IIS), X, Y, width, height); </P> <p> // Save the new image <br/> If (null! = Outputimage) {<br/> ImageIO. write (outputimage, "jpg", new file (tarpath); <br/>}< br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}</P> <p> Public static bufferedimage getsubimage (bufferedimage inputimage, int X, int y, int width, int height) {<br/> return getsubimage (inputimage, new rectangle (X, Y, width, height )); <br/>}</P> <p> Public static bufferedimage getsubimage (bufferedimage inputimage, rectangle rect) {<br/> If (rect. x <1 | rect. Y <1 | rect. x> inputimage. getwidth () | rect. y> inputimage. getheight () {<br/> return NULL; <br/>}< br/> int x = math. min (inputimage. getwidth (), rect. x); <br/> int y = math. min (inputimage. getheight (), rect. y); <br/> int width = math. min (inputimage. getwidth ()-X, rect. width); <br/> int Height = math. min (inputimage. getheight ()-y, rect. height); <br/> return inputimage. getsubimage (X, Y, width, height); <br/>}