转换BMP类型

时间:2013-11-14 10:59:36

标签: java image types bufferedimage

我试图转换bmp:

File file = new File(source.getText());

    try {
        BufferedImage i = ImageIO.read(file);
        if (i != null) {

            BufferedImage convertedImg = new BufferedImage(i.getWidth(), i.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
            boolean drawImage = convertedImg.getGraphics().drawImage(i, 0, 0, null);

                File f = new File(output.getText().concat(File.separatorChar + "out.bmp"));
                boolean write = ImageIO.write(convertedImg, "BMP", f);
        } else {
            //...
        }
    }catch (Exception e) {
            e.printStackTrace();
    }

但它没有正确地写入图像。当我打开bmp它说文件是空的?我做错了什么?

编辑:write返回false。

0 个答案:

没有答案