java 图片裁剪指定大小

   public static void main(String[] args) throws IOException {
        String srcFileName = "D:\\派大星.jpg";
        String path = "D:\\派大星2.jpg";
        zoomImage(srcFileName,path, 512, 512);
        System.out.println("    -->  ok  <--    ");
    }

    /**
     * 改变图片尺寸
     * @param srcFileName 源图片路径
     * @param path        图片修改后路径
     * @param width       修改后的宽度
     * @param height      修改后的高度
     */
    public static void zoomImage(String srcFileName,String path,int width,int height){
        try {
            BufferedImage bi = ImageIO.read(new File(srcFileName));
            BufferedImage tag=new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
            tag.getGraphics().drawImage(bi, 0, 0, width, height, null);
            ImageIO.write(tag, "jpg", new File(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

你可能感兴趣的:(java 图片裁剪指定大小)