glue Vertical BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Crop

Description

glue Vertical BufferedImage

Demo Code


//package com.java2s;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage glueVertical(BufferedImage[] images) {
        int w = 0;
        int h = 0;
        for (BufferedImage image : images) {
            if (images != null) {
                w = Math.max(w, image.getWidth());
                h += image.getHeight();/*from   ww w .j  av a 2 s. co  m*/
            }
        }
        BufferedImage result = new BufferedImage(w, h,
                BufferedImage.TYPE_INT_ARGB);
        int y = 0;
        Graphics2D g = result.createGraphics();
        for (BufferedImage image : images) {
            if (images != null) {
                g.drawImage(image, 0, y, null);
                y += image.getHeight();
            }
        }
        g.dispose();
        return result;
    }
}

Related Tutorials