Java 中的 BufferedImage 到 BMP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3961687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:10:27 来源:igfitidea点击:
BufferedImage to BMP in Java
提问by Eduardo Abreu
I have a BufferedImage object and I want to encode it to the BMP format and save it to disk.
我有一个 BufferedImage 对象,我想将它编码为 BMP 格式并将其保存到磁盘。
How do I do this?
我该怎么做呢?
In JPEG
it's ok:
在JPEG
它的确定:
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();
回答by Faisal Feroz
Something like this should do:
这样的事情应该做:
ImageIO.write(image, "BMP", new File("filename.bmp"));
where image is the BufferedImage you want to encode.
其中 image 是您要编码的 BufferedImage 。