我调整了图像的大小,但它的质量很低。我听说过双三次插值,但我无法获得任何实现代码。这是我的代码:
private static BufferedImage resize(BufferedImage image, int width, int height)
{
int w = image.getWidth(), h = image.getHeight();
int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
BufferedImage resizedImage = new BufferedImage(width, height, type);
Graphics2D g = resizedImage.createGraphics();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
//g.drawImage(image, 0, 0, width, height, null);
g.scale((double)width/w,(double)height/h);
g.drawRenderedImage(image, null);
g.dispose();
return resizedImage;
}
我想在上采样和下采样后获得最好的质量。