开发者

BufferedImage to BMP in Java

开发者 https://www.devze.com 2023-01-20 20:19 出处:网络
I have a BufferedImage object and I want to enc开发者_StackOverflow中文版ode it to the BMP format and save it to disk.

I have a BufferedImage object and I want to enc开发者_StackOverflow中文版ode 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();


Use ImageIO -

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


Something like this should do:

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

where image is the BufferedImage you want to encode.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号