java 在java中将bmp转换为jpg
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10837292/
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
converting bmp to jpg in java
提问by Jeel Shah
How do you convert bmp to jpg in Java? I know how to use the ImageIO
way but is there a much faster or better way of doing it?
你如何在Java中将bmp转换为jpg?我知道如何使用这种ImageIO
方式,但有没有更快或更好的方法呢?
This is the ImageIO way of doing that I found on the web.
这是我在网上找到的 ImageIO 方法。
`//Create file for the source
File input = new File("c:/temp/image.bmp");
//Read the file to a BufferedImage
BufferedImage image = ImageIO.read(input);`
//Create a file for the output
File output = new File("c:/temp/image.jpg");
//Write the image to the destination as a JPG
ImageIO.write(image, "jpg", output);
If I use this way will I lose quality?
如果我使用这种方式,我会失去质量吗?
Thanks
谢谢
回答by mprivat
Yes you will. Actually regardless of the way to convert a BMP (lossless) to JPG (lossy) you always lose quality. You can limit the damage if you set the JPG quality to 100% (which kind of defeats the purpose in my opinion).
是的你将会。实际上,无论将 BMP(无损)转换为 JPG(有损)的方式如何,您总是会失去质量。如果将 JPG 质量设置为 100%,则可以限制损坏(在我看来,这违背了目的)。
Use this tutorialto fix it.
使用本教程来修复它。