glue Horizontal BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Crop

Description

glue Horizontal BufferedImage

Demo Code


//package com.java2s;

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

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

Related Tutorials