java png gif bmp to jpg

原文链接:https://my.oschina.net/u/2296689/blog/545790
File file = new File("d:/temp/1.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();

转载于:https://my.oschina.net/u/2296689/blog/545790

上一篇:将Color设置为int值以便在setRGB(int x,int y,int rgb)方法中使用? — Java


下一篇:java-BufferedImage旋转,更改结果背景