Java BufferedImage Slice sliceImage(BufferedImage img, int verticalSize)

Here you can find the source of sliceImage(BufferedImage img, int verticalSize)

Description

slice Image

License

Open Source License

Declaration

public static List<Object[]> sliceImage(BufferedImage img, int verticalSize) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Object[]> sliceImage(BufferedImage img, int verticalSize) {

        List<Object[]> images = new ArrayList<>();

        int start = 0;
        int end = verticalSize;
        int total = img.getHeight();
        int slices = total / verticalSize + (total % verticalSize == 0 ? 0 : 1);

        for (int i = 0; i < slices; i++) {

            start = i * verticalSize;/*w  w  w  . ja  va  2  s  .c  o  m*/
            end = start + verticalSize - 1;

            if (end > total - 1) {
                end = total - 1;
            }

            images.add(new Object[] { img.getSubimage(0, start, img.getWidth(), end - start + 1) });

        }

        return images;

    }
}

Related

  1. sliceImage(BufferedImage img, int cols, int rows)