纯java代码 改变图片的大小

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;


public class xiaotu
{
        public static void createSmallPhoto() throws IOException{
            File _file=new File("C:\\Users\\wuzhengya\\Desktop\\领红包\\guoqi.png");
            Image src;
            src=javax.imageio.ImageIO.read(_file);
            int wideth=110;
            int height=80;
            
            BufferedImage tag=new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB);
            tag.getGraphics().drawImage(src, 0, 0, wideth, height,null);
            FileOutputStream out=new FileOutputStream("D:\\新建文件夹\\1.2.png");
            JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out);
            encoder.encode(tag);
            out.close();
            
        }
        
        public static void main(String[] args) throws IOException
        {
            xiaotu.createSmallPhoto();
        }
}

你可能感兴趣的:(纯java代码 改变图片的大小)