0

I have been researching this for a while on this site and have not came up with exactly what I am looking for. I am working with software in which I do not have the source for must pass that code an Image.class image. I have 2 images that I need to overlay the first one over the second and then pass that combined image to the software I am interfacing with. I must use the Java Language for all code.

Everything I have found is writing the 2 images directly. Is what I am trying to do possible and if so please can you help me get these results? A code stub would be wonderful. I surely appreciate all of the time you take in assisting me.

rJLodi
  • 1
  • 1
  • I'm not totally clear what you're asking - are you trying to figure out how to merge images? or use the software that you don't have the source for? Or something else? Can you post some code representing what you've tried so far? – Krease Nov 23 '13 at 19:44
  • What I was trying to do is take 2 images, merge them into 1 image; then, pass that 1 image to the cots software using their function which is foo(Image image). – rJLodi Nov 23 '13 at 19:53

1 Answers1

0

Basically, you can "paint" one image on to the other...The trick is getting one of them into the correct format...

Image image1 = ...;
Image image2 = ...;
BufferedImage buffer1 = new BufferedImage(image1.getWidth(this), image1.getHeight(this), BufferedImage.TYPE_ARGB);
Graphics2D g = buffer.createGraphics();
g.drawImage(image1, 0, 0, this);
g.drawImage(image2, 0, 0, this);
g.dispose();

This will overlay image2 over image1. You can either assign buffer1 to image1 and pass it to you other class or simple pass buffer1 as BufferedImage extends from java.awt.Image

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • I will see if this worked. It looks like once I get the graphics by using the buffer, all the drawImage calls will draw the icon to the buffer. That is where I think I got lost. – rJLodi Nov 23 '13 at 19:50
  • Yep, basically, this just paints each image onto the `BufferedImage`'s `Graphics` context...If you are using `java.awt.Icon`, the process is little different, but the concept is the same... – MadProgrammer Nov 23 '13 at 21:49