Hey, DW. I really need to know how to combine two images, into one image, but I don't want to draw it to the screen, and I don't want to save it to a file. It should look something like this

Image img1 = new ImageIcon("C:\\flying.png").getImage();
Image img2 = new ImageIcon("C:\\foo.png").getImage();

Image combined = img1 + im2;

Thanks so much you guys :)

Image combined = img1 + img2;

this is ... wow ..
1. you can't create your Images like that, since (in java terms) ImageIcon does not pass an 'is-an-Image' test
2. you can't combine Images with the '+' operator. next to numerical tasks, there is not that much more you can do with them, besides (for instance) concatenating String objects.

I never had to do anything of the sort, and since the errors in your declarations, I assume you haven't tried to compile what you have either, so my first question would be:

did you bother to Google 'java append two images'?
I'm pretty sure you'll get hundreds (if not thousands) of examples that can help you on your way.

"...but I don't want to draw it to the screen, and I don't want to save it to a file."
Well... What's the point???

"...but I don't want to draw it to the screen, and I don't want to save it to a file."
Well... What's the point???

It's an applet, so I can't save to their computer, unless it's a drive-by, which it isn't.

Do you mean join side-by-side, or overlay one image on top of the other?

Not side by side really. I have 2 transparency enabled PNGs where one image is on top of the other(overlayed)

Edited 5 Years Ago by glut: incase people get confused, because they do so often.

Read the first into a buffered image, get that image's Graphics2D, draw the second image on to it. You'll find the documentation in the usual places.

(but, I still don't understand what you're going to do with this in an applet if you don't display it on the screen?)

Edited 5 Years Ago by JamesCherrill: n/a

Read the first into a buffered image, get that image's Graphics2D, draw the second image on to it. You'll find the documentation in the usual places.

(but, I still don't understand what you're going to do with this in an applet if you don't display it on the screen?)

Thank you, you're the first one on this thread that actually tried to help. And what are you saying about the applets? Can applets not do this?

Yes they can, but if you don't display it or save it what are you going to do with it?

Eventually I am going to draw it to the screen, but I want to manipulate it before and after displaying it :)

This article has been dead for over six months. Start a new discussion instead.