Salut:
Ici, j'ai supposé que tu es en train de manipuler un objet BufferedImage.
public class BufferedImageSplitter {
public static BufferedImage[] split(BufferedImage bi) { BufferedImage[] bis = new BufferedImage[4]; for (int i = 0; i < 4; ++i) { int w = bi.getWidth()/2; int h = bi.getHeight()/2; int x = w*(i%2); int y = h*(i/2); bis[i] = bi.getSubimage(x, y, w, h); } return bis; } public static void saveImage(BufferedImage bi, String filename, String format) throws IOException{ ImageIO.write(bi, format, new File(filename)); } public static void main(String[] args) { try { BufferedImage bi = ImageIO.read(new File("image.jpg")); BufferedImage[] bis = split(bi); for (int i = 0; i < bis.length; ++i) { saveImage(bis[i], "img" + i + ".jpg", "jpg"); } } catch (IOException e) { e.printStackTrace(); } } }
|