在Java中将BMP转换为JPG

3

如何在Java中将bmp转换为jpg?我知道如何使用ImageIO方法,但是否有更快或更好的方法呢?

以下是我在网上找到的使用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);

如果我使用这种方式,会失去质量吗?
谢谢。

3
我建议使用PNG而不是JPG。这样你仍然可以得到比BMP更小的图像,但不会失去图像质量。 - Devon_C_Miller
1个回答

4

是的,无论如何将BMP(无损)转换为JPG(有损),都会失去质量。如果将JPG质量设置为100%,可以限制损坏(但在我看来有点违背了初衷)。

使用此教程进行修复。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接