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

    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
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    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
    Posts
    34
    Rep Power
    0

    Default

    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
    Posts
    266
    Rep Power
    5

    Default

    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
    Posts
    20
    Rep Power
    0

    Default

    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(),
    				BufferedImage.TYPE_INT_RGB);
    		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, 06:49 AM
  2. Update existing buffered image
    By rosh72851 in forum New To Java
    Replies: 24
    Last Post: 12-04-2008, 03: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
  •