Java BufferedImage Create getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2, int yImage2)

Here you can find the source of getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2, int yImage2)

Description

Mezcla dos imagenes en una sola, sobreponiendo la segunda en la primera.

License

Apache License

Parameter

Parameter Description
imageFormat String.- png, jpg.
image1 BufferedImage
image2 BufferedImage
xImage2 int
yImage2 int

Exception

Parameter Description
IOException an exception

Return

BufferedImage

Declaration

public static BufferedImage getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2,
        int yImage2) 

Method Source Code


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

import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class Main {
    /**//  ww  w  .j  a v  a  2  s . c  o m
     * Mezcla dos imagenes en una sola, sobreponiendo la segunda en la primera.
     * @param imageFormat String.- png, jpg.
     * @param image1 BufferedImage
     * @param image2 BufferedImage
     * @param xImage2 int
     * @param yImage2 int
     * @return BufferedImage
     * @throws IOException
     */
    public static BufferedImage getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2,
            int yImage2) {
        // create the new image, canvas size is the max. of both image sizes
        int w = Math.max(image1.getWidth(), image2.getWidth());
        int h = Math.max(image1.getHeight(), image2.getHeight());
        BufferedImage mixedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);//BufferedImage.TYPE_INT_ARGB);

        // paint both images, preserving the alpha channels
        Graphics g = mixedImage.getGraphics();
        g.drawImage(image1, 0, 0, null);
        g.drawImage(image2, xImage2, yImage2, null);

        return mixedImage;
    }
}

Related

  1. getBufferedImageBytes(BufferedImage bufferedImage)
  2. getBufferedImaged(Image img, int width, int height)
  3. getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height)
  4. getBufferedImageFromFile(String fileName)
  5. getBufferedImageFromPath(String path)
  6. getBufferedImageType(String encodeType)