Java下载图片二. 通过ImageIO类实现

ImageIO.write(ImageNew, "png", outFile);// 写图片

中间的参数支持:png,jpg,gif (暂只支持这几种,其他的不支持)

 

各种不同格式分类传输:

    import java.awt.image.BufferedImage;  
    import java.io.File;  
    import java.io.IOException;  
    import java.net.URL;  
      
    import javax.imageio.ImageIO;  
      
    public class WriteImage {  
        public static void main(String[] args) {  
            BufferedImage image = null;  
            try {  
      
                URL url = new URL("http://www.google.com/logos/classicplus.png");  
                image = ImageIO.read(url);  
      
                ImageIO.write(image, "jpg", new File("E:\\Test\\classicplus.jpg"));  
                ImageIO.write(image, "gif", new File("E:\\Test\\classicplus.gif"));  
                ImageIO.write(image, "png", new File("E:\\Test\\classicplus.png"));  
      
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
            System.out.println("Done");  
        }  
    }  

 各种不同格式统一传输:

 

你可能感兴趣的:(Java,java,image,download)