Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Rep Power

    Default How to attach two BufferedImage to obtain 1 buffered image

    I have a serious trouble to attach two bufferedimage and need to obatain one image from that.. Someone please sudjest me a method...

    BuffereImage img1, img2;

    Final output should be one image which contain addition of both images... So i should be able to see the both images...

    Thank you in advance.....

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    San Jose, CA, USA
    Rep Power


    1) Create a new Buffered Image with size appropriate to fit the two images.
    2) Get the graphics object from the new Buffered Image ('img3.createGraphics();')
    3) Draw img1 and img2 to img3 via the graphics object.
    My Hobby Project: LegacyClone

  3. #3
    Join Date
    Mar 2009
    Rep Power


    Alryt i think i get u... in my case size of the all the images are same..... they are stored in an array callled...

    BufferedImage img[2] ;

    then i m confuse with what u said about concatanation part.... How i can use your code line

    img3.createGraphics(); part to usefully done my taks....

    Please help me...

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Rep Power


    Suppose we want to join the images horizontally, so I'm assuming their heights are the same.

    Java Code:
    BufferedImage b1;   // available to you already
    BufferedImage b2;   // available to you already
    BufferedImage result;
    // if TYPE_INT_ARGB doesn't work for you, play with the other constants
    result = new BufferedImage (b1.getWidth()+b2.getWidth(), b1.getHeight(), BufferedImage.TYPE_INT_ARGB);    
    Graphics g = result.getGraphics ();
    g.drawImage (b1, 0, 0, null);
    // drawing b2 where b1 ended
    g.drawImage (b2, b1.getWidth (), 0, null);
    g.dispose ();
    // at this point, "result" is ready to go.

  5. #5
    hero is offline Member
    Join Date
    Jul 2009
    Rep Power


    This should place the images just next to eachother..

    Java Code:
    public BufferedImage attachImages(BufferedImage img1, BufferedImage img2)
    		BufferedImage resultImage = new BufferedImage(img1.getWidth() +
    				img2.getWidth(), img1.getHeight() + img2.getHeight(),
    		Graphics g = resultImage.getGraphics();
    		g.drawImage(img1, 0, 0, null);
    		g.drawImage(img2, img1.getWidth(), 0, null);
    		return resultImage;

Similar Threads

  1. how can i attach a worg/image file
    By sniffer139 in forum AWT / Swing
    Replies: 4
    Last Post: 03-12-2010, 07:49 AM
  2. Update existing buffered image
    By rosh72851 in forum New To Java
    Replies: 24
    Last Post: 12-04-2008, 04:43 AM
  3. Unable to draw buffered image
    By pedjasmek in forum Java 2D
    Replies: 7
    Last Post: 08-08-2008, 03:49 PM
  4. Replies: 0
    Last Post: 07-02-2008, 08:06 PM
  5. Replies: 1
    Last Post: 06-07-2007, 05:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts