/** * * @param source 源图片路径 * @param formatName 将要转换的图片格式 * @param result 目标图片路径 */ public static void convert(String source, String formatName, String result) { try { File f = new File(source); f.canRead(); BufferedImage src = ImageIO.read(f); ImageIO.write(src, formatName, new File(result)); } catch (Exception e) { e.printStackTrace(); } }
调用:
convert("C:\\timg.jpg", "png", "C:\\time.png");