publicstaticvoidcrop(InputStream input, OutputStream output, int x, int y, int w, int h, boolean isPNG) throws Exception { try { BufferedImage srcImg = ImageIO.read(input); int tmpWidth = srcImg.getWidth(); int tmpHeight = srcImg.getHeight(); int xx = Math.min(tmpWidth - 1, x); int yy = Math.min(tmpHeight - 1, y);
int ww = w; if (xx + w > tmpWidth) { ww = Math.max(1, tmpWidth - xx); } int hh = h; if (yy + h > tmpHeight) { hh = Math.max(1, tmpHeight - yy); }
BufferedImage dest = srcImg.getSubimage(xx, yy, ww, hh);
BufferedImage tag = new BufferedImage(w, h, isPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
publicstaticvoidcrop(InputStream input, String result, int x, int y, int w, int h, boolean isPNG) throws Exception { try { BufferedImage srcImg = ImageIO.read(input); int tmpWidth = srcImg.getWidth(); int tmpHeight = srcImg.getHeight(); int xx = Math.min(tmpWidth - 1, x); int yy = Math.min(tmpHeight - 1, y);
int ww = w; if (xx + w > tmpWidth) { ww = Math.max(1, tmpWidth - xx); } int hh = h; if (yy + h > tmpHeight) { hh = Math.max(1, tmpHeight - yy); }
BufferedImage dest = srcImg.getSubimage(xx, yy, ww, hh);
BufferedImage tag = new BufferedImage(w, h, isPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);