日期:2014-05-19 浏览次数:20610 次
/** * 改变图片大小 * * @param img * @param weight * @param height * @return */ public BufferedImage modifySize(BufferedImage img, int width, int height) { try { int w = img.getWidth(); int h = img.getHeight(); double wRation = (new Integer(width)).doubleValue() / w; double hRation = (new Integer(height)).doubleValue() / h; Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH); AffineTransformOp op = new AffineTransformOp(AffineTransform .getScaleInstance(wRation, hRation), null); image = op.filter(img, null); img = (BufferedImage) image; } catch (Exception e) { e.printStackTrace(); } return img; }