Adding two BufferedImages without painting on screen?

Hi all,
I am trying to combine two (or more) BufferedImages into onee BufferedImage, such that the result is a BufferedImage that represents all the images laid out side-by-side. (If I get a result for two images I can work out multiple images by myself)
This would be quite simple if I were interested in displaying the images, as I could extend a JPanel or JLabel or whatever, and modify the paint() or paintComponent() method to paint out all the BufferedImages. I could then use this to create a new BufferedImage if I wanted.
However, I want to be able to create a BufferedImage (or a Byte Array) without ever needing to paint the images on the screen. I need to be able to save the resulting BufferedImage/byet[] without needing to pop up a little panel to paint on.
Is there any way to do this?
Thanks!
Sam

Here is my implementation along the lines suggested. I assume all images are the same size. I have only actually tested this code for the case where rows = columns.
/** Combines an list of images into a new bigger buffered image.
    * The images in the list should be in 'across then down' order (like a regular GridLayout).
    * We assume that all the images in the array
    * are the same size as the first one.
    * If rows * columns is bigger than the size of
    * the array then some of the resulting image will remain black. 
    * If rows * columns is less, then
    * some of the images in the list are unused.
   public static BufferedImage tileBufferedImages(List<BufferedImage> bis, int rows, int columns)
      if (bis==null || bis.size()==0) throw new IllegalArgumentException("images must be provided");
      int height = bis.get(0).getHeight();
      int width = bis.get(0).getWidth();
      BufferedImage combo = new BufferedImage(width * columns,
               height * rows, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = combo.createGraphics();
      int i=0;
      for (int r= 0 ; r < rows; ++r) for (int c = 0; c < columns; ++c)
         if (i< bis.size())
            g2.drawImage(bis.get(i), c*width, r*height, null);
         ++i;
      g2.dispose();
      return combo;
   Edited by: RobWall on Nov 27, 2007 12:39 AM
Edited by: RobWall on Nov 27, 2007 8:37 PM

Similar Messages

  • Adding two BufferedImages together?

    Is there anyway to "for lack of a better word add two bufferedImages together?
    For example if I have a JLabel with an ImageIcon thats a red square 32 x 32 pixels and another JLabel with an ImageIocn thats a green square also 32 x 32 pixels. Can I create a new ImageIcon thats 64 x 32 pixels that is the red square and green square together?
    Something like new BufferedImage(image1, image2,  concanate_xaxis);Thanks,
    Cathal.
    cathal87

    Ive tryed to impliment your above suggestion camickr, but all I can seem to get as output is a black image.
    Heres some code that demonstrates my problem.
    Once the following code is compiled and run an image is created using all of the JLabels ImageIcons from the JFrame and its saved into a file at "C:/Image.png". Obviously this would have to be changed for testing purposes depending on ones OS and Drive letter preferences.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.*;
    public class Example2
           static JFrame frame;
           static JLayeredPane layeredPane;
           public static void main(String[] args)
                  frame = new JFrame("Example");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setResizable(false);
                  frame.setSize(320, 320);
                  frame.setLocationRelativeTo(null);
                  frame.getContentPane().setLayout(null);
                  layeredPane = new JLayeredPane();
                  layeredPane.setOpaque(true);
                  layeredPane.setLayout(null);
                  layeredPane.setBounds(0, 0, 320, 320);
                  frame.setContentPane(layeredPane);
                  for(int i = 0; i < 32; i ++)
                          for(int j = 0; j < 32; j ++)
                               JLabel label = new JLabel(new ImageIcon("images/grass.gif"));
                               layeredPane.add(label, new Integer(0));
                               label.setBounds(i * 32, j * 32, 32, 32);
                  frame.setVisible(true);
                  createAndSaveImage();
           public static void createAndSaveImage()
                  BufferedImage image = new BufferedImage(320, 320, BufferedImage.TYPE_INT_RGB);
                  Component[] components = layeredPane.getComponentsInLayer(0);
                  int count = 0;
                  for(int i = 0; i < 32; i ++)
                          for(int j = 0; j < 32; j ++)
                                  JLabel label = (JLabel)components[count];
                                  label.getGraphics().drawImage(image, i, j, 32, 32, null);
                                  count ++;
                  try
                        ImageIO.write(image, "png", new File("C:/Image.png"));
                  catch(Exception exexe)
    }

  • To add two new fields in CO09 SCREEN

    Hi All,
    I have a requirement of adding two new fields  Customer Name and Number (Sold to party) for the MRP Elements IN CO09 Screen which is already there in MD04.
    Please let me know as soon as possible if any one has any idea regarding this.

    Hi All,
    I have the same issue. Any solution already in sight?
    KR,
    Martin

  • How to add one or two photos without synchronise my 8240 photos on my ipad2

    How to add one or two photos without synchronize my 8240 photos on my ipad2 or iPhon4 ?
    Thank you

    Just add the photos to the folders/location that you last synced and sync them - as only the contents of the last photo sync remains on the iPad, you have to (re-)sync all the photos that you want on the iPad. In theory only the new photos will need processing by the sync process, so it shouldn't take a long time to sync (it hasn't for me when I've added a few to my 1500 photos in the past anyway). Not including photos in a sync is how you remove them from the iPad.
    Your alternative is to email them to yourself and then save them from the email, but they will only go into the Saved Photos/Camera Roll album - come iOS 5 in the Autumn you should then be able to move photos between albums.

  • I accidentally added two .doc files, they show in iTunes file sharing, but don't show on iPad?

    I accidentally added two .doc files by dragging and dropping into itunes, under my device, then the app tab, then file sharing for Adobe Reader, they show in iTunes file sharing window, but don't show on iPad 3, and I cannot delete them on iTunes screen? Please help!

    First, I would advise you to apply Tao philosophy to this. Given the dysfunction of most software, if this was just an accidental copy and you don't want them on iPad and they are not showing up anyway, what's the problem? Forget it. It's not worth the hassles. I'm more concerned that you have psychological issues you need to be dealing with, not this. You are making much too unnecessary work and stress for yourself.
    As for deleting them, I'm assuming you highlighted them and hit delete and it didn't work. If not, it should. Works for me. But if it doesn't, my advice is also not to worry about it, as annoying as the clutter is. It will eventually resolve itself (like when your data files corrupt or your iPad crashes, LOL. (I apologize for my cynicism but I am fed up with dysfunctional software). It's not worth the hassles of trying to figure out petty issues.
    As for me, I have the opposite, and very serious problem. I've got Reader on my iPad too. But I can't move the pdfs out of it and onto my laptop with iTunes' dysfunctional file sharing. I get the error "file cannot be copied because you do not have permission to see its contents." I have hundreds of pdfs on my iPad that I converted from web surfing with other programs that also don't work and I can't get them off the iPad for backup and to have a synced library I can access from both laptop and iPad.
    I called iTunes twice and both times they blamed it on the app, saying iTunes file sharing doesn't support third party apps and that I should call Adobe and talk them into writing the code that will work with iTunes. Yeah, right. And Reader is not the only problem. This is happening with iAnnotate and Write PDF and other apps.
    I suspect that both of us have the root problem, perhaps Apple's greedy refusal to support the apps that it sells in the app store and are quasi-integrated enough to show up in the file sharing documents list, but can't be moved or deleted; and the apps that don't bother to make their apps fully work with iTunes file sharing.
    If anyone has any solutions ......

  • Workaround to adding two e-mail alias accounts with same username.

    I have two e-mail addresses (aliases) (for example [email protected] and [email protected]) running under one (same) username "jimmy" and the same password on the same mail server (basically one e-mail account with two e-mail address aliases). I wanted to have both added to my iPad running iOS 5. I added the first without a problem, but when I tried to add the second one, the iPad complained that an account with the username "jimmy" already exists and gave me a prompt window with two options, "Cancel" and "Edit". Cancel was supposed to cancel the whole e-mail account creating procedure and take me back to Settings/Mail, and "Edit" was supposed to take me back to editing this e-mail account so I could change it (select another username). It turned out that both "Cancel" and "Edit" threw me out of the editing procedure and put me back into Settings/Mail. Seems like a bug.
    I managed to use a workaround to add my second e-mail address account (alias) to the iPad 2 with the same account username. I started creating the second account and filled in all the information but I intentionally mystyped the username as "jimmo". Now when I tapped "Done" the iPad wanted to verify the account (as normal) but soon warned me that either the username or password were incorrect and that the account may not work correctly, but it did allow me to add it.  I then went in and edited this second account and changed it's incoming mail server username to "jimmy".
    Now I have both e-mail addresses (aliases) using one account correctly set-up. Just thought I'd write this in case anyone would encounter the same problem/bug.

    EDIT: When using Mail application to check e-mails I am getting sporadic "Cannot Get Mail: The user name or password for "<name_of_account> is incorrect." The password is correct and it works when I retry. If I disable one of the accounts in the Settings/Mail (set to Inactive) then the other one (using the same password on the same server) works without hiccups. They definitely have to work on this bug and fix it.

  • Query for Linking Two Tables without Reference

    Hi Folks,
    Good Day!
    I have this dilemma on how to link two tables without a reference. In the Business Partner Master Data, there is a field for the Territory which is from the table OTER. This OTER focuses on its description. Once you have added the particular Territory for that Business Partner, it is being stored in the Territory field of the BP right? Our client wants to have an automated way of searching for the Business Partner's Profit Center in creating a Sales Order wherein it is the same as the Business Partner's Territory. The Profit Center is from the table OPRC.
    When I create a Sales Order, after I have entered the Business Partner/Customer Code, the Profit Center should have the value of the Profit Center Code wherein it is the Business Partner's Territory. My query will go like this:
    Enter the BP/Customer Code automatically the Profit Center code where Profit Name = BP's Territory.
    OTER and OCRD don't have connections. How can it be?
    I'm thinking of retrieving the Territory first before the Profit Center but can you suggest of any other way?
    Thank you much!
    Regards,
    Fringe

    Hi Fringe,
    Okay, I already understood your case here. I presume your configuration as follows:
    OTER (Territory)
    territryID - descript
    1 - Philippine
    2 - Indonesia
    3 - Germany
    OPRC (Cost Centre)
    PrcCode - PrcName
    25 - Philippine
    33 - Indonesia
    47 - Germany
    Was above illustration correct? Then, you could use this formatted search in Cost Centre / Dimension field in Sales Order rows
    SELECT PrcCode FROM OPRC WHERE PrcName=(
    SELECT TOP 1 descript FROM OTER T0
    INNER JOIN OCRD T1 ON T0.territryID=T1.Territory
    WHERE T1.CardCode=$[OCRD.CardCode.0])
    However, I suggest you use a little bit different approach here. Since you can't define Territory Code / Territory ID (you could only type the Territory name, Philippine etc.), why don't you standardize Territory name with Cost Centre code? Let say, you define Philippine as PHI, Indonesia as INA, Germany as DEU and so on. Therefore, user can read the Cost Centre or more precisely Distribution Rules in Sales Order form in more familiar way.
    OTER (Territory)
    territryID - descript
    1 - PHI
    2 - INA
    3 - DEU
    OPRC (Cost Centre)
    PrcCode - PrcName
    PHI - Philippine
    INA - Indonesia
    DEU - Germany
    When FMS worked in Sales Order document, your user will read PHI instead of 25, should be more familiar to them. With that being said, you could use simpler FMS
    SELECT descript FROM OTER T0
    INNER JOIN OCRD T1 ON T0.territryID=T1.Territory
    WHERE T1.CardCode=$[OCRD.CardCode.0]
    You only need to maintain consistency between Territory Name and Cost Centre code. Just my two cents. Hope this help.
    Best Regards,
    Hendry Wijaya

  • I have duplicate pictures in "my catalog" that I believe come from two Adobe folders found under "my pictures/adobe/ one is Revel and the other is Photoshop express which preceded revel. Can I delete those two folder without causing a problem with my cata

    I have duplicate pictures in "my catalog" that I believe come from two Adobe folders found under "my pictures/adobe/ one is Revel and the other is Photoshop express which preceded revel. Can I delete those two folder without causing a problem with my catalog?

    Thanks for the links, Limnos.
    If you are willing to continue helping, here's what I found.
    Just to clarify the two iTunes folders I am refering to are:
    username-->Music-->iTunes
    HD-->iTunes
    I am presuming each location has a full set of files as outlined in the above links?
    Not all the files are in both locations. Most are.
    - The Itunes folder in my home folder does not have itunes library.xml.
    - The Itunes folder in my home folder has a subfolder called Mobile Applications (username-->Music-->iTunes--> Mobile application). The Itunes folder at the HD level also has a Mobile Application folder but it is a subfolder of Itunes Media folder (HD-->iTunes--> iTunes Media-->Mobile applications) and has no files in it.
    - I do not have an iTunes Media in the iTunes folder in my home folder.
    - also the Itunes media folder (HD-->iTunes--> iTunes Media) has subfolders by type (books, movies, itunes u, music etc...) but the iTunes Media-->Music also has some of the same subfolders ( iTunes Media-->Music-->books, iTunes Media-->Music-->Movies, iTunes Media-->Music-->iTunes U). Is this normal repetition?
    You say:
    /itunes/itunes media/ music
    but it is important to note what comes before all that.
    There is nothing as far as I can tell before that first forward slash. Since the only iTunes Media folder I have is in the iTunes folder that resides at the HD level (HD-->iTunes--> iTunes Media folder) not the iTunes folder in my home folder (username-->Music-->iTunes) , I assume that's the one that holds the music.
    Keep iTunes media folder organized and Copy files to iTunes Media folder when adding to library are both checked on
    Does that give more clarity into my problem?

  • Select criteria without using SELECTION SCREENs

    Hi everybody,
    I have a report with a single screen, 4 fields for search criteria and 2 alv grids for the output.
    I search db tables with a select statement.
    Is it possible to define a select statement that searches for 3 out of 4 criteria, if the fourth input field isn't filled it?
    Because right now the select statement doesn't return any data if I leave one parameter blank.
    And how can I provide the possibility to define more than one search criteria of one kind withour adding several input fields on the screen?
    For example: Data created on 20070101 and 20070105.
    I know that most of this can be done with selection screens, but is there a possibility to do this without a selection screen?
    Best regards
    Tobias

    You should use SELECT-OPTIONS on your selection screen.  This allows the user to enter all kinds of possiblities, including leaving something blank.  Then in your SELECT statement, you use the IN operator.
    select-options: s_datum for sy-datum.
    select * into table itab
               from ztable
                      where datum IN s_datum.
    If you truly do not want to use a Selection-screen, you could hard code values in the SELECT statement or create a range using the RANGE statement.  The RANGE statement works exactly like SELECT-OPTION statement but without the selection-screen.
    Regards,
    Rich Heilman

  • I have Two Icons at the Login screen I want to remove one how do I do that?

    I have Two Icons at the Login screen I want to remove one how do I do that? I am Migrating a PC to a Mac Mini and the migration hung.  I ran it again and I now have two login Icons.  One has all my migrated files and the other does not. I want to remove the one without the files.
    Thanks

    Open System Preferences>Users & Groups, unlock the lock, highlight the one you don't want click on the little minus icon.

  • Wouldl like to use an large external with my mac book-if so how can I shut the lid without losing the screen?

    Wouldl like to use an large external with my mac book…if so how can I shut the lid without losing the screen?

    This is the article on the subject:
    Mac notebooks: How to use your computer in closed clamshell (display closed) mode with an ...
    But it does not cool as well when closed. I suggest you arrange your workflow across the two screens side to side, or put the Big Display up on blocks and open the laptop below it, and use both screens in Extended Desktop:

  • I manually added two rows in error. How do i delete them?

    Help, I manually added two rows, but cannot find out how to delete them without deleting all the responses!

    Hi;
    You can delete a single, or multiple rows in the Response Table by clicking on the row (or selecting multiple rows by clicking on the first row and then Shift+Click on the last row you want to select) and either using the right click context menu item "Delete Row/s" or clicking the arrow that appears when you mouse over the left side of the row/s and selecting "Delete Row/s" from the menu:
    Thanks,
    Josh

  • Is there a way to make the icon/words larger on the screen without changing the screen resolution?

    Is there a way to make the icons/words larger on the screen without changing the screen resolution?

    If you right-click in the top of title bar of any  Finder window there is an option to un-check 'use small icon size', though toggling between the two makes little difference on my screen.
    Another trick is you can zoom the whole screen by holding down the 'control' key and using a two-finger swipe up on the trackpad to enlarge, down to go back to normal.

  • When I try to setup my iCloud, after adding my AppleID & password, the next screen is the EULA (with an Agree and a Disagree button) - I press Agree - Nothing happens.  It appears to freeze.

    When I try to setup my iCloud, after adding my AppleID & password, the next screen is the EULA (with an Agree and a Disagree button) - I press Agree - Nothing happens.  It appears to freeze.  This phone was previously owned and the last owner's apple id is what defaults...  I do not know the last owner's password. - I just want to get rid of that person's iCloud in order to create my own with my own account.

    With iOS 7 you will not be able to delete the iCloud account without providing the password for the iCloud ID.  If it is the previous owner's account, you will need to have them remove it from their ID as mentioned in this article: http://support.apple.com/kb/TS4515.

  • I bougnt my S5 a month ago and I am having two major issues.  The screen is very slow to respond.  When the screen is dark and I press the home button, it doesn't come on.  I have to press the button anywhere from 4-10 times and then it usually flashes on

    I bougnt my S5 a month ago and I am having two major issues.  The screen is very slow to respond.  When the screen is dark and I press the home button, it doesn't come on.  I have to press the button anywhere from 4-10 times and then it usually flashes on and back off.  It is very, very frustrating.  The other issue is that the battery drains very quickly.  I have called Verizon numerous times regarding these issues.  They tell me to do different things that never help.  We eventually did a factory reset and it still has the same issues.  Help!  It is a brand new phone and unfortunately I am in a new two year contract.  Ugh. Is there anyone out there who can help me?

    I have done that several times.  In fact, every time I call Verizon with my phone problems, they have me do the same things repeatedly.  I keep telling them I have already done them but they insist they are SURE it will work this time.  It never does.  After doing the factory reset and it still not working correctly, they act like they are confused, almost like I am lying.  I did what you suggested above on the slim chance it would work this time but it did not.  I bought two S5's that day and the other one works perfectly fine.  I know I got a bad phone.  Verizon just does not listen.  It is a bad phone.  I just want a new phone that works properly.  Is that too much to ask?  I bought a new phone that has been bad from day one.  Why oh why do I have to spend hours of my time on the phone, in the store, on the computer, trying to rectify this?  It shouldn't be this difficult!  Help please!!!

Maybe you are looking for

  • ACTIONS ON ALV REPORT FOR CHECKBOX?

    hi All, i have to display ALVreport with one of the columns has checkbox.whenever user presses any checkbox,in repected row values have to be validated and updated in DataBase. My First Doubt is,How can i get the column of checkBoxes in ALV Report.?

  • Is this true?

    https://mobilepanel2.nielsen.com/nenroll/rewards.d​o?l=en_in&pid=1 i have got mail to this link stating Nokia and neilsens site...is it true frnds? or just spam?

  • Check in to CVS

    Hi, Can any one help what files need to check in to CVS for BPEL process project ? thanks, Bharath

  • Confusion on 2.4 and 5Ghz bands

    Hi All, So I just picked up the new TC with the 802.11ac. When I set it up, there was a checkbox in AE to create a seperate 5GHz network. I went ahead and checked it and now my network shows up twice, with one showing 5Ghz at the end of the name. So

  • 11.2 crashing every time on open

    Following the latest update to 11.2 iTunes will not stay running and crash before I can plug in and sync.... HELP. I did try renaming the iTunesPrefs.xml file located in "C:\Users\mjacob\AppData\Roaming\Apple Computer\iTunes" and then relaunced succe