Java BufferedImage Merge mergeImage(BufferedImage a, BufferedImage b)

Here you can find the source of mergeImage(BufferedImage a, BufferedImage b)

Description

merge Image

License

Open Source License

Declaration

public static BufferedImage mergeImage(BufferedImage a, BufferedImage b) 

Method Source Code


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

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage mergeImage(BufferedImage a, BufferedImage b) {
        BufferedImage img = new BufferedImage(800, 600, 1);
        Dimension dim = new Dimension(img.getWidth(), img.getHeight());
        Graphics g = img.getGraphics();

        for (int r = 0; r < dim.width; r++) {
            for (int c = 0; c < dim.height; c++) {
                //System.out.println("row: " + r + " col: " + c);
                Color ac = new Color(a.getRGB(r, c));
                Color bc = new Color(b.getRGB(r, c));

                g.setColor(new Color((ac.getRed() + bc.getRed()) / 2, (ac.getGreen() + bc.getGreen()) / 2,
                        (ac.getBlue() + bc.getBlue()) / 2));
                g.fillRect(r, c, 1, 1);/*from w  w w  .  j av a 2 s  .c o  m*/
            }
        }

        return img;
    }
}

Related

  1. mergeImage(BufferedImage origImage, Vector fadedImages)
  2. mergeImages(List images, int space, Color bg)