如何在Java中调整.bmp图像的大小?

时间:2014-06-29 06:22:54

标签: java image image-processing bmp

所以我尝试使用以下代码调整.bmp图像的大小:

void resizeSeenAreaToFitRetina(String BMPImageFileName, int newWidth, int newHeight) throws IOException {
    BufferedImage bmpImage = ImageIO.read(getClass().getResource(BMPImageFileName));
    Image scaledBMPImage = bmpImage.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST);
    BufferedImage scaledBufferedBMPImage = (BufferedImage) scaledBMPImage; // I know I can't do this but ImageIO.write(only_takes_BufferedImage_class_here, ...)
    ImageIO.write(scaledBufferedBMPImage, "bmp", new File("ResizedArray2DTest.bmp"));
}

如何将已调整大小的图像写入文件?