我使用的代码是下一个:
public BufferedImage res20x20(BufferedImage image){
int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
BufferedImage resizedIm= new BufferedImage(20, 20, type);
Graphics2D g= resizedIm.createGraphics();
g.drawImage(image, 0, 0, 20, 20, null);
g.dispose();
g.setComposite(AlphaComposite.Src);
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
return resizedIm;
}
可以找到整个代码here。 结果我想要的是:
答案 0 :(得分:1)
试试这个
public BufferedImage res20x20(BufferedImage image){
int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
BufferedImage resizedIm= new BufferedImage(20, 20, type);
Image scaledImage = inputImage.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
resizedIm.getGraphics().drawImage(scaledImage, 0, 0, null);
return resizedIm;
}
Image.SCALE_SMOOTH
是用于缩放图像的算法类型,您可以尝试使用不同的值来获得更好地满足您需求的结果