将BufferedImage转换为另一种类型

时间:2011-11-19 12:32:27

标签: java image-processing

从源(FileInputStreamURL s)读取图片的最便捷方法是:

BufferedImage myImage = ImageIO.read( source );

但是,如何将myImage转换为BufferedImage.TYPE_USHORT_565_RGB格式?

1 个答案:

答案 0 :(得分:29)

您可以创建所需类型的新BufferedImage,然后在其上绘制原始图像,如:

    BufferedImage bufImg = ImageIO.read( imageURL );
    BufferedImage convertedImg = new BufferedImage(bufImg.getWidth(), bufImg.getHeight(), BufferedImage.TYPE_USHORT_565_RGB);
    convertedImg.getGraphics().drawImage(bufImg, 0, 0, null);