public class PicConver {
public static void main(String[]args) throws IOException{
File file = new File("d:/temp/n14719577.bmp");
Image img = ImageIO.read(file);
BufferedImage tag = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(img.getScaledInstance(img.getWidth(null), img.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);
FileOutputStream out = new FileOutputStream("d:/temp/bmp2jpg.jpg");
// JPEGImageEncoder可适用于其他图片类型的转换
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
}
}
public static void main(String[]args) throws IOException{
File file = new File("d:/temp/n14719577.bmp");
Image img = ImageIO.read(file);
BufferedImage tag = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(img.getScaledInstance(img.getWidth(null), img.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);
FileOutputStream out = new FileOutputStream("d:/temp/bmp2jpg.jpg");
// JPEGImageEncoder可适用于其他图片类型的转换
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
}
}
图像转换与压缩技术
本文介绍了将位图文件转换为JPEG格式的过程,包括使用Java ImageIO库读取图像,创建新的BufferedImage对象进行缩放,并使用JPEGImageEncoder进行格式转换。
768

被折叠的 条评论
为什么被折叠?



