墨色风雨
不幸的是,getScaledInstance()的性能很差,如果没有问题的话。另一种方法是创建一个新的BufferedImage,并在新的BufferedImage上绘制原始的缩放版本。BufferedImage resized = new BufferedImage(newWidth, newHeight, original.getType());Graphics2D g = resized.createGraphics();g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);g.drawImage(original, 0, 0, newWidth, newHeight, 0, 0, original.getWidth(),
original.getHeight(), null);g.dispose();newWidth,newHL.8表示新的BufferedImage大小,并且必须正确计算。在因素比例方面:int newWidth = new Double(original.getWidth() * widthFactor).intValue();int newHeight = new Double(original.getHeight() * heightFactor).intValue();