Java Image Cut cutImage(String src, String dest, int x, int y, int w, int h)

Here you can find the source of cutImage(String src, String dest, int x, int y, int w, int h)

Description

cut Image

License

Open Source License

Declaration

public static void cutImage(String src, String dest, int x, int y, int w, int h) throws IOException 

Method Source Code


//package com.java2s;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

public class Main {
    public static void cutImage(String src, String dest, int x, int y, int w, int h) throws IOException {
        Iterator iterator = ImageIO.getImageReadersByFormatName("jpg");
        ImageReader reader = (ImageReader) iterator.next();
        InputStream in = new FileInputStream(src);
        ImageInputStream iis = ImageIO.createImageInputStream(in);
        reader.setInput(iis, true);//from  w  w w . j  av  a  2  s. c  o m
        ImageReadParam param = reader.getDefaultReadParam();
        Rectangle rect = new Rectangle(x, y, w, h);
        param.setSourceRegion(rect);
        BufferedImage bi = reader.read(0, param);
        ImageIO.write(bi, "jpg", new File(dest));

    }
}

Related

  1. cut2(String srcImageFile, String descDir, int rows, int cols)
  2. cutImage(BufferedImage image, int posX, int posY, int width, int height)
  3. cutImage(BufferedImage img, int w, int h)
  4. cutImage(File file, int x, int y, int width, int heigth)
  5. cutImage(final BufferedImage bufferedImage, final int targetW, final int targetH)
  6. cutImage(String src, String dest, int x, int y, int w, int h)