0

I am working as a Spring MVC developer. My requirement is to set multiple small images on different positions over a big image.

For example I have a big image and some small images. I have the coordinates and height/width of the small images. I would like to set these small images on that big image over different coordinates. Finally I have to save the image with small images over it.

I have tried to play with buffered image but I actually didn't get how to do this. Please help me and provide any simple code to do this if possible.

Thank you in advance.

    File f = new File(fullPath+"/"+imageHotSpot.getImageObject().getFilePath());
    BufferedImage buff1 = ImageIO.read(f);
    Graphics2D g2d = buff1.createGraphics();
    File statusicon = new File(bigStatusIcon);
    BufferedImage buff2 = ImageIO.read(statusicon);    
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));    
    g2d.drawImage(buff2, 10, 10,null);                                     
    g2d.dispose();
    File outputfile = new File(fullPath+"/images/hotspotimages/image.jpg");
    ImageIO.write(buff1, "jpg", outputfile);
  • See the Oracle Java2D [Working with images](http://docs.oracle.com/javase/tutorial/2d/images/) tutorial. It covers all you need. – Harald K Jan 29 '16 at 08:25
  • Thank you for reply ...i had read this blog but i didn't get that how can i set multiple images over a single big image . so please provide code if possible . – vipin kumar Jan 29 '16 at 08:59
  • If you want help with code, show what you have tried. As written in the help center: You must *include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself.* PS: If you know how to compose a single image over another, you just need a loop to compose multiple images. – Harald K Jan 29 '16 at 09:07
  • 1
    Possible duplicate of http://stackoverflow.com/questions/10055005/how-to-draw-an-image-over-another-image – STaefi Jan 29 '16 at 09:07
  • i attached the code which i had tried to do . i don't know how to compose a single image to another . so please can you elaborate this . – vipin kumar Jan 29 '16 at 09:22
  • The code you have posted seems fine. It does compose a single image (`buff2`) onto another (`buff1`) and stores the result as a JPEG. Now, just add a loop to it, and you are composing multiple images. – Harald K Jan 29 '16 at 09:31
  • Thank You i got it . thanks for your support . :) – vipin kumar Jan 29 '16 at 09:47

0 Answers0