Question

I've been looking for a solution for the last several days.

I've seen an example of composite images with Java Advanced Imaging. But that seems to be restricted by the smallest width and height of either image files. So it outputs a file with the height and width of the header file.

Preferably, I'd like to have the header not covering any part of the body image. But it's not a requirement. Sometimes the body image's width is smaller than the header and that's fine as the main content of the header file will be in the middle.

Using JDK 1.6.0_41, I need to take the first two images:

header_image

Body image

And have the result be:

Final result

Whether it is using Java or Javscript is fine. The entire process is as follows:

I take a canvas object of a map using OpenLayers, then use a POST to send it to a Java Servlet to be processed and stored. Then later retrieved the image if the user desires.

The long blue header needs to be at the top of an image or just above it. The header image will have content from the user that created it, etc. That I can do. But manipulating multiple images is not something I am familiar with.

Was it helpful?

Solution

In Java, you can do this:

public BufferedImage prependImage(BufferedImage image1, BufferedImage image2) {
    Dimension d1 = new Dimension(image1.getWidth(null),
            image1.getHeight(null));
    Dimension d2 = new Dimension(image2.getWidth(null),
            image2.getHeight(null));
    Dimension dt = new Dimension(d1.width, d1.height + d2.height);

    BufferedImage image = new BufferedImage(dt.width, dt.height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();

    int x = 0;
    int y = 0;
    g.drawImage(image1, x, y, d1.width, d1.height, null);
    y += d1.height;
    g.drawImage(image2, x, y, d2.width, d2.height, null);
    g.dispose();

    return image;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top