我想调整一个缓冲图像的大小。我已经成功地将其存储并在jframe上显示,但是似乎无法调整其大小。您有什么提示可以帮助我解决这个问题并将图像显示为一个200x200的文件呢?
private void profPic(){
String path = factory.getString("bottle");
BufferedImage img = ImageIO.read(new File(path));
}
public static BufferedImage resize(BufferedImage img, int newW, int newH) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
Graphics2D g = dimg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
g.dispose();
return dimg;
}
TYPE_INT_ARGB
而不是img.getType()
? - ADTC