BufferedImage to BMP in Java

◇◆丶佛笑我妖孽 提交于 2019-11-27 06:53:49

问题


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();

回答1:


Use ImageIO -

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



回答2:


Something like this should do:

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

where image is the BufferedImage you want to encode.



来源:https://stackoverflow.com/questions/3961687/bufferedimage-to-bmp-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!