java在做圖片類型轉換時,JDK本身提供的類對 GIF->JPG GIF->PNG PNG->GIF(X) PNG->JPG 這幾種類型的轉換支持比較好,可以通過類直接轉,代碼如下:
- /**
- * Created on 2010-7-13
- * <p>Discription:[convert GIF->JPG GIF->PNG PNG->GIF(X) PNG->JPG ]</p>
- * @param source
- * @param formatName
- * @param result
- * @author:[[email protected]]
- */
- 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();
- }
- }