JAVA supports image cropping and java supports image cropping.
1/** 2 * crop an image 3 * @ param src Source image 4 * @ param dest the cropped image 5 * @ param x the X coordinate of the cropping range 6 * @ param y the Y coordinate of the range is 7 * @ param w the height of the crop range is 8 * @ param h the width of the crop range is 9 * @ param destW the width of the cropped image is 10 * @ param deth the cropped Image height of 11 * @ throws IOException12 */13 public static void cutImage (String src, string dest, int x, int y, int w, 14 int h, int destW, int deth) throws IOException {15 try {16 17 // unknown problem, I don't know why \ r \ n18 19 src = src will end up in the path. Replace ("\ r \ n", ""); 20 dest = dest. replace ("\ r \ n", ""); 21 System. out. println ("CutImage: src =" + src + "; dest =" + dest + "; x =" + x + "; y =" + y ); 22 File file = new File (src); 23 if (file. exists () {24 Iterator <ImageReader> iterator = ImageIO. getImageReadersByFormatName ("jpg"); 25 ImageReader reader = (ImageReader) iterator. next (); 26 InputStream in = new FileInputStream (src); 27 ImageInputStream iis = Imag EIO. createImageInputStream (in); 28 reader. setInput (iis, true); 29 ImageReadParam param = reader. getDefaultReadParam (); 30 Rectangle rect = new Rectangle (x, y, w, h); 31 param. setSourceRegion (rect); 32 BufferedImage bi = reader. read (0, param); 33 if (w! = DestW) {// stretched or reduced by 34 bi. flush (); 35 BufferedImage newImage = new BufferedImage (destW, deth, bi. getType (); 36 Graphics g = newImage. getGraphics (); 37g. drawImage (bi, 0, 0, destW, deth, null, null); 38g. dispose (); 39 ImageIO. write (newImage, "jpg", new File (dest); 40} else {41 ImageIO. write (bi, "jpg", new File (dest); 42} 43 iis. close (); 44 in. close (); 45 // Delete the temporary file 46 file. delete (); 47} else {48 System. out. println ("the file to be cropped cannot be found: FileName =" + src); 49} 50} catch (Exception ex) {51 ex. printStackTrace (); 52} 53}CutImage