BufferedImage to BMP in Java

2019-01-19 16:43发布

I have a BufferedImage object and I want to encode it to the BMP format and save it to disk.

How do I do this?

In JPEG it's ok:

BufferedImage img; //here is an image ready to be recorded into the hard disk
FileOutputStream fout = new FileOutputStream("image.jpg");

JPEGImageEncoder jencoder = JPEGCodec.createJPEGEncoder(fout);
JPEGEncodeParam enParam = jencoder.getDefaultJPEGEncodeParam(img);

enParam.setQuality(1.0F, true);
jencoder.setJPEGEncodeParam(enParam);
jencoder.encode(img);

fout.close();

2条回答
爷、活的狠高调
2楼-- · 2019-01-19 16:46

Use ImageIO -

ImageIO.write(img, "BMP", new File("filename.bmp"))
查看更多
ら.Afraid
3楼-- · 2019-01-19 16:54

Something like this should do:

ImageIO.write(image, "BMP", new File("filename.bmp"));

where image is the BufferedImage you want to encode.

查看更多
登录 后发表回答