Java BufferedImage Split splitVertically(BufferedImage top, int elements)

Here you can find the source of splitVertically(BufferedImage top, int elements)

Description

split Vertically

License

Apache License

Declaration

public static BufferedImage[] splitVertically(BufferedImage top, int elements) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Graphics2D;
import java.awt.Rectangle;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage[] splitVertically(BufferedImage top, int elements) {
        int currentY = 0;
        int stepY = top.getHeight() / elements;
        BufferedImage[] images = new BufferedImage[elements];
        for (int i = 0; i < elements; i++) {
            images[i] = croppedCopy(top, 0, currentY, top.getWidth(), currentY + stepY);
            currentY += stepY;/*from w w w  .j av a2  s  .co  m*/
        }
        return images;
    }

    public static BufferedImage croppedCopy(BufferedImage image, int startX, int startY, int endX, int endY) {
        int width = endX - startX;
        int height = endY - startY;
        BufferedImage cropped = new BufferedImage(width, height, image.getType());
        Graphics2D graphics2d = cropped.createGraphics();
        graphics2d.drawImage(image, 0, 0, width, height, startX, startY, endX, endY, null);
        graphics2d.dispose();
        return cropped;
    }

    public static BufferedImage croppedCopy(BufferedImage championRow, Rectangle rect) {
        return croppedCopy(championRow, rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
    }
}

Related

  1. splitImage(BufferedImage img, int cols, int rows)
  2. splitImage(BufferedImage img, int rows, int cols)
  3. splitImage(final Image img, final int rows, final int cols)
  4. splitImage2D(BufferedImage img, int cols, int rows)
  5. splitImageIntoTiles(final BufferedImage imageWithTiles, final int numberOfTilesAcross, final int numberOfTilesDown)
  6. tileStretchPaint(Graphics g, JComponent comp, BufferedImage img, Insets ins)