0

I'm in a situation where I'm not allowed to use AWT libraries on a server but need to merge two images. I know only of one method in Java which is using java.awt.Graphics.drawImage and java.awt.image.BufferedImage.

Is it possible to merge two images not using AWT?

AWT-based example code:

try {
    BufferedImage image = ImageIO.read(new File("a.png"));
    BufferedImage overlay = ImageIO.read(new File("b.png"));

    int width = Math.max(image.getWidth(), overlay.getWidth());
    int height = Math.max(image.getHeight(), overlay.getHeight());

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

    g.drawImage(image, 0, 0, null);
    g.drawImage(overlay, 0, 0, null);

    ImageIO.write(combination, "png", new File("c.png"));
}
catch (IOException ioe) {
}
  • 1
    How do you mean? [Compositing](http://en.wikipedia.org/wiki/Compositing)? – Elliott Frisch Mar 31 '14 at 19:12
  • 2
    Are you sure you don't just want to run java headless? http://www.oracle.com/technetwork/articles/javase/headless-136834.html – rainkinz Mar 31 '14 at 19:27
  • Added source code. Unfortunately, I'm very explicitly not allowed to use AWT. –  Mar 31 '14 at 19:49
  • 1
    *"I'm very explicitly not allowed to use AWT."* Very explicitly ***why?*** If you don't know, find out! This answer cannot be adequately answered without understanding the 'why?'. – Andrew Thompson Apr 01 '14 at 06:01

2 Answers2

0

Yes, it is possible, but why?

Read: Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot? here you will be able to find many others GUI frameworks which could be useful for you.

Community
  • 1
  • 1
Mitro
  • 1,230
  • 8
  • 32
  • 61
  • *"..many others GUI frameworks.."* Not one of which will work on a headless server. That is (99.3% sure) why the OP 'cannot use AWT' - though a better spec. from them would certainly help. – Andrew Thompson Apr 01 '14 at 05:58
  • You are probably right. I haven't ever used none of them in headless server, but he just sayd that he can't use AWT. Reading Sounds unexpected, but actually you can perform different operations in this mode, even with graphic data. from java documentation. I suppose (hope) that it is possible with another GUI framework. Tell me if I'm wrong ;) – Mitro Apr 01 '14 at 06:52
0

Have you considered ImageJ?

It is an open source, pure Java image processing library.

Chris
  • 694
  • 3
  • 18
  • 1
    I'd bet that most image APIs in existence would use some of the AWT API, which means they would not work in a headless server (where anything AWT is ruled out). – Andrew Thompson Apr 01 '14 at 05:59