JAVA保存图像

import java.io.*;
import java.awt.image.*;
import java.awt.*;
import javax.imageio.*;
import javax.swing.*;

class A{
    public static void main(String[] args)
        throws Exception{

        Image img=new ImageIcon("nh.gif").getImage();
    
        int width = img.getWidth(null);
        int height = img.getHeight(null);
        BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
        Graphics g = bi.getGraphics();
        g.drawImage(img,0,0,width,height,null);
        g.dispose();
        File f = new File("myimage.jpg");
        ImageIO.write(bi, "jpg", f);
    }
}

你可能感兴趣的:(java)