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)
}

Similar Messages

  • Adding two arrays together

    I am trying to add two arrays together, it does not seem as if the arrays are broken up into more than one index. I have attached my code. If the array is broken up into indexes I would like to add each corresponding index, but I think the array is all in just one index and if so I was wondering how would I break it into indexes. Thanks
    Attachments:
    SimpleTest x1.vi ‏336 KB

    Since you are "transposing" and later work with 1D array, I assume you want to read the first column of the file.
    Why do you need a sequence stacked 5 frames deep, local variables, 5 instances of the same boolean diagram constant and 5 path conststants of which some are identical??? None of this is needed!
    All you need is probably something along the lines of the following picture, which probably does something similar to what you want. Still, we are probably still jumping through too many flaming hoops. Note that the execution order is uniquely defined by the wiring alone, no sequence needed! Can you take a step back and tell us what you are actually trying to achieve with all this? How many columns are in the file? Only one?
    Message Edited by altenbach on 01-27-2009 04:02 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    AddArraysFromFile.png ‏13 KB

  • Adding two sums together

    Post Author: nickyboyc
    CA Forum: Formula
    Hi guys, I'm very new to Crystal reports and having what I'm sure is a simple problem. I'm getting data from a Oracle Database via ODBC and I've created some summaries and groups and the final piece in my jigsaw is I want to add two sums together and for the life of me I can't find out how to do it. I've tried and tried and I just can't get it to work.They are in a group and the 2 sums are :
    Sum ({WMLocnHandlingMediaConf.QtyStor}
    and
    Sum ({WMLocnHandlingMediaConf.QtyIn}Many thanks in advance Nick

    Post Author: yangster
    CA Forum: Formula
    just create a formula with your 2 sums in there@sum
    Sum ({WMLocnHandlingMediaConf.QtyStor}+
    Sum ({WMLocnHandlingMediaConf.QtyIn}

  • 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

  • Seeing a problem adding two numbers together (or I've lost my mind)

    I have a resource adapter that provides support for an implementation of the (RDP) Reliable Datagram Protocol (RFC 908/1151) that I wrote. I'm having a problem when this is deployed to a SunFire V480 with 4 CPUs running Glassfish 9.1u2 with JDK 1.6.0_05.
    Basically what I am seeing is that when I add 1 to a number sometimes it works and sometimes it does not. So I am losing my mind and I am hoping someone here can help me see the errors in my ways.
    The protocol uses sequence numbers similar to TCP. So in my code, when I receive a RDP message it need to check to see that the sequence number matches what is expected. Basically an instance of a class that represents a connection maintains the last sequence number seen and the message coming in had better have this sequence number plus 1.
    Here is the code that I'm having a problem with:
    +if (__LOGPROTO.isLoggable(Level.FINER)) {+
    __LOGPROTO.finer("receiveMessage inmsg.seq = " inmsg.getSequenceNumber() + " __rcvcur = " + __rcvcur + " SEQ_PLUS = " + SEQ_PLUS(__rcvcur, 1) + "this = " + this);+
    +}+
    +if (inmsg.getSequenceNumber() == SEQ_PLUS(__rcvcur, 1)) {+
    +if (inmsg.getDataLength() > 0) {+
    +// Save the data+
    ackMsg = new RDPAckMessage(inmsg);
    __rcvdList.add(ackMsg);
    +if (__LOGPROTO.isLoggable(Level.FINER)) {+
    __LOGPROTO.finer("receiveMessage message queued to user " this);+
    +}+
    notifyReceivable = true;
    +// Signal that there is data available+
    __signal.setValue(true);
    +}+
    __rcvcur = inmsg.getSequenceNumber();
    +// Now see if we have any out of order segments that can+
    +// be queued to the user+
    for (i = 0; i < __rcvrcvdseqno.length; i+) {+
    +if (__rcvrcvdseqno != null) {+
    if (__rcvrcvdseqno != null && SEQ_EQ(__rcvrcvdseqno.getSequenceNumber(),
    +SEQ_PLUS(__rcvcur, 1))) {+
    +__rcvcur = __rcvrcvdseqno] 0) {+
    +// Move over to the received list+
    ackMsg = new RDPAckMessage(__rcvrcvdseqno);
    +if (__LOGPROTO.isLoggable(Level.FINER)) {+
    __LOGPROTO.finer("receiveMessage ood message queued to user " this);+
    +}+
    __rcvdList.add(ackMsg);
    notifyReceivable = true;
    +// Signal that there is data available+
    __signal.setValue(true);
    +}+
    __rcvrcvdseqno = null;
    +}+
    +}+
    +}+
    +} else {+
    +if (__LOGPROTO.isLoggable(Level.FINER)) {+
    __LOGPROTO.finer("xxx receiveMessage inmsg.seq = " inmsg.getSequenceNumber() + " __rcvcur = " + __rcvcur + " SEQ_PLUS = " + SEQ_PLUS(__rcvcur, 1) + "this = " + this);+
    +}+
    I have a couple of log messages that I put in to help try to figure out what in the heck is going on. The first prints out the message sequence number, the last sequence number that was known (__rcvcur), and the result of a method called SEQ_PLUS which passes in "__rcvcur" and '1".
    Here is the SEQ_PLUS code:
    +private long SEQ_PLUS(+
    +long x,+
    +long y) {+
    +long z = (x + y) % 0x100000000L;+
    +return z;+
    +}+
    Basically what I am seeing is that SEQ_PLUS is correctly adding 1 to "__rcvcur" on one call and then not adding 1 in the next.
    Here is the log messages that occur. Note that "this" is the same in all of the log messages, that the thread is the same in all log messages, but in one instance SEQ_PLUS works and another it does not.
    +[#|2008-09-23T11:04:49.580-0400|FINER|sun-appserver9.1|com.canoga.lib.io.rdp.RDPConnection.msg|_ThreadID=30;_ThreadName=RDPConnectionEngineUDP;ClassName=com.can+
    +oga.java.io.rdp.RDPConnection;MethodName=receiveMessage;_RequestID=e6876cf2-0fb9-4de3-938a-484eee9a2b7a;|receving msg[<ACK> from=1024 to=1787 datalen=5 seq=16839 ack=1355376372] by RDPConnection(com.canoga.java.io.rdp.RDPConnection@125f069):/172.16.142.16|#]+
    +[#|2008-09-23T11:04:49.581-0400|FINER|sun-appserver9.1|com.canoga.lib.io.rdp.RDPConnection.proto|_ThreadID=30;_ThreadName=RDPConnectionEngineUDP;ClassName=com.c+
    +anoga.java.io.rdp.RDPConnection;MethodName=receiveMessage;_RequestID=e6876cf2-0fb9-4de3-938a-484eee9a2b7a;|receiveMessage inmsg.seq = 16839 __rcvcur = 16838 SEQ_PLUS = 16839this = RDPConnection(com.canoga.java.io.rdp.RDPConnection@125f069):/172.16.142.16|#]+
    +[#|2008-09-23T11:04:49.581-0400|FINER|sun-appserver9.1|com.canoga.lib.io.rdp.RDPConnection.proto|_ThreadID=30;_ThreadName=RDPConnectionEngineUDP;ClassName=com.c+
    +anoga.java.io.rdp.RDPConnection;MethodName=receiveMessage;_RequestID=e6876cf2-0fb9-4de3-938a-484eee9a2b7a;|xxx receiveMessage inmsg.seq = 16839 __rcvcur = 16838 SEQ_PLUS = 16838this = RDPConnection(com.canoga.java.io.rdp.RDPConnection@125f069):/172.16.142.16|#]+
    I am at a loss as to how this could occur. I'm hoping some bright mind can see what I cannot.
    Any help will be greatly appreciated.
    Brett

    Actually the nested code in the follow up is a SCCE:
                                if (__LOGPROTO.isLoggable(Level.FINER)) {
                                    __LOGPROTO.finer("xxx receiveMessage inmsg.seq = " + inmsg.getSequenceNumber() + " __rcvcur = " + __rcvcur + " SEQ_PLUS = " + SEQ_PLUS(__rcvcur, 1L) + "this = " + this);
                                    long x = __rcvcur;
                                    long y = 1;
                                    long z = (x + y) % 0x100000000L;
                                    __LOGPROTO.finer("xxx x is " + x + " y is " + y + " z is " + z);
                                }There is nothing in this snippet that should allow "y" to be anything other than the value '1" which it is initialized to, no matter how many threads, cpu's, etc there may be since "x, y, and z" are stack local variables and "y' is never assigned to after it is initialized. The output of the log message shows however that sometimes it is different:
    [#|2008-09-23T12:15:38.505-0400|FINER|sun-appserver9.1|com.canoga.lib.io.rdp.RDPConnection.proto|_ThreadID=28;_ThreadName=RDPConnectionEngineUDP;ClassName=com.c
    anoga.java.io.rdp.RDPConnection;MethodName=receiveMessage;_RequestID=77189b23-d5ff-49c3-8194-662f468bbe66;|xxx x is 16838   is 4294967296 z is 16838|#]This code is within a very large Java EE application running under the Glassfish application server. The problem manifests itself about
    about 1 of every 4 starts of the application server and I have only seen it occur on Solaris on my V480 server.
    So if someone can explain how "y" becomes "4294967296" I would very thankful.

  • Adding two time figures together

    Please forgive me I am not familiar with FormCalc or Javascript.
    I am creating a form for work and I need to add two time figures minutes and seconds (IE 02:30 + 02:30) I have looked all over the web and I can not find anything that is working,
    I can add the two figures together but I get (ie 4:60)
    please any help you can give will be be wonderful

    Hi Chris,
    No need to shout.
    Formula in column C (calculates the Duration (time elapsed) between two Date and Time values:
    =B-A
    Formula in column D (Calculates the same Duration as above, but subtracts 30 minutes if the total Duration is greater than 5 hours):
    =IF(DUR2HOURS(B-A)>5,B-A-DURATION(,,,30,,),B-A)
    Note that any cell displaying a Date or a Time (of day) or both contains a Date and Time value.
    If only the Date has been entered, the time part is set to 00:00:00 (midnight, at the beginning of that day).
    If only the Time has been entered, the date part is set to the date the entry was made.
    In the table above, the values in Row 18, the bottom row of the table are as follows:
    A18: March 1, 2012 11:00:00 AM
    B18: March 1, 2012 5:00:00 PM
    C18: 6h
    D18: 5h 30m
    The first two are Date and Time values, the second two are Duration values.
    Regards,
    Barry

  • Tie two songs together

    I'd like to be able to tie two songs together so they always play back to back, yet in a complete shuffle mode. For instance Van Halen's Eruption / You Really Got Me Down. They appear as separate songs on the CD, so they play randomly on the shuffle. Is there a way to tie pairs of songs together?
    Thanks

    You can join tracks when importing from the CD. Insert your CD highlight the songs you want to join and choose "Join CD Tracks" from the Advanced menu and import: Adding songs from CDs to your library

  • 'Merge Cell' is greyed out - how do I activate it and merge two cells together?

    I am just learning Numbers, trying to merge two cells together should be a very simple process!
    I have followed the instructions in help
    The 'merge cells' function remains greyed out no matter what I do - I therefore cannot merge two or more cells into one!
    Please help, is there something I need to activate in the cell?

    Hi Claudia,
    Actually, a "truly blank document" would be an empty canvas, containing no table of any type, no document header or footer locations, no document margins, no page definitions, no page orientation. Just a blank sheet onto which you could put whatever objects you wish.
    Perhaps Apple should have named the 'not blank' templates "Basic" rather than blank, removed the header column, and left the header row intact. That would match the "Basic" table style available in the Tables button's menu, used for adding a table to a Sheet.
    If you really do want to always start with a table which has no header rows and no header columns, it's easy enough to set up.
    Open a new 'blank' document (Apple's 'blank').
    Click on the Table 1 icon in the Sheets list and press delete. (faster than selecting cell A1, then taking two trips to the Table menu to delete first the (header) row then the (header) column)
    Click the Tables button and choose Plain to insert a 'plain' table (no header row, no header column)
    (optional) Add or delete rows or columns to make the blank table the size you desire.
    (optional) Position the table where you want it.
    Save the result as a Template.
    In Numbers Preferences > General > For New Documents, select Use Template, then Choose your new template.
    Until you change that preference, any New document you make will contain your new, 'blank' table.
    Regards,
    Barry

  • 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 ......

  • How do I connect two lines together.

    I have two lines at an angle but where the corner of the angle is supposed to be there is a little triangle missing. I tried joining the two lines together but when I hit join one line goes past the other.
    Before Joining:
    After Joining:

    There is no need to lock one of the paths, because you do not have to tediously select endpoints just to join paths. Doing so was necessary in Illustrator for most of its history, but it finally (decades behind other drawing programs) gained the ability to join paths at their nearest endpoints by just selecting the paths.
    Undo (or cut) the unwanted join.
    Black pointer: Select the left and right paths.
    Join.
    Alternativley, when drawing line art, it is not uncommon to set your default Graphic Style to use rounded endcaps. That negates the problem of the "missing triangle" (as you call it) appearance of coincident straight end caps.
    JET

  • How do I "fuse" two photos together in elements?

             I would like to "fuse" two photos together; how do I do this in elements?http://[email protected]

    Please amplify what you are trying to do.
    Do you wish to add an object from photo A to photo B, for example?

  • Problem araised in  adding two custom fields to ksb1 tcode.

    hi experts,
      I added tow fields vendor no, vendor name to Tcode:KSB1.
    i used user-exit :   coomep01 .
    in this exit i added two fields to ci_rkpos (include table) . i.e zlifnr,zname1.
    but that problem is ci_rkpos is not appearing in green color it means it is not transported .
    in development  client is working properly .
    using sm34 i added fields names.
    error is coming like this.
    The following syntax error occurred in the program SAPLXKAEP :
    "The data object "CS_RECORD" has no component called "ZLIFNR", but ther"
    Error in ABAP application program.
    The current ABAP program "SAPLKAEP" had to be terminated because one of the
    here wat ever we add the zfields will appear in kaep_coac ,so in this structure two added fields are appeared in dev client
    but,the same zfields when transported to quality is not appearing .
    please suggest how to do??

    hi breakpoint.
    yes i attached  in transport.
    in quality client.
    wat ever i wriiten code  in user exit it is coming ,but
    incldue table structure is not coming ,and even that fields are appearing in v_tkalv ,but in structure kaep_coac
    blank include strcuture CI_RKPOS is appearing ,but
    in dev client is working properly, and in quality first of all report is going to dump.
    here this tvode is using all 3 plants,how can i restrict to specified plant so that ,it will not affect others plant.
    suggest me how to do??
    Edited by: kamalsac on Aug 18, 2010 10:57 AM

  • Linking Two Folders Together

    Hi,
    I have a 13" MacBook Air Mid 2013, 128GB, 4GB RAM, 1.3 GHz, OS X 10.10 Yosemite.
    When I put a folder in iCloud Drive, the folder is in iCloud Drive and on my Desktop. What I want to do is link the two folders together so when I save a file in the folder on my desktop, it puts it in the folder that's in iCloud Drive too. I hope I have explained this good enough.
    Please help.
    Thanks

    If you own both and have admin accounts on them, yes. On the "other" computer, go to System Preferences, Sharing, and turn on File Sharing.
    When the two computers are on the same network, you should see the other computer appear in your sidebar in Finder. Click it, authenticate with your admin details (from the other computer), and you now have access to its files.
    Matt

  • Linking two switches together.

    hi Guys ,
    quick question in relation to joining two switches together,
    can I link a 2950 switch with a 1000 BASE-SX with a 3560G with 4 SPF ports with fibre and what pitfalls should i look out for .
    Thanks in advance
    Kevin

    Hello,
    So you would like to connect GBIC to SFP, you need Multimode Duplex Fiber Optical cable with SC-LC connectors. If SFP to SFP you need the same cably type with LC-LC connectors.
    http://www.cisco.com/en/US/products/hw/routers/ps341/prod_module_installation_guide09186a00801cc731.html
    http://cisco.com/en/US/products/hw/modules/ps5455/products_data_sheet09186a008014cb5e.html
    bye
    FCS
    Please rate me if I helped.

  • Linking two accounts together

    Are you able to link two accounts together.  For example, I have had an account for a long time, but now my husband has one as well as my son.  My son is currently signed in with my account but I would like to give him his own as well as share what I have with my husband.
    Thanks,
    Stephanee

    Sorry, but it is not possible to merge iTunes Store accounts. You can, however, use content from multiple iTunes Store acounts on any given system or device. You just have to authorize the device to each account. You will have to use the account though which any item was purchased for redownloading, app updates, etc.
    Regards.

Maybe you are looking for

  • Problems syncing and lots of "Other" data

    I have a 32gb iPod Touch 5th gen running iOS 7. I have 2 major issues, as stated in the title. The first is with syncing. As iTunes goes through the steps it gets stuck on "Waiting for items to copy" or "Waiting for changes to be applied;" whichever

  • Greek/math symbols do not display in Lion though working correctly in Snow Leopard.

    I am attempting to edit/use powerpoint presentations created in Office 2011 on Snow Leopard. Though my math and Greek symbols display perfectly correctly on my Snow Leopard laptop, they do not display on my Lion desktop. Instead, they are replaced wi

  • Please Help! Invalid Drive: E:\

    I currently have itunes 6 but for the last few months, whenever i have tried to install a more up to date version it says 'Invalid Drive: E:\' This is after the 'Run' process and on the final installation phase. I really want the newest version as i

  • Oracle Database 10g Release 2 (10.2.0.1.0)  on window vista

    Hi All, Pls help me to find out can we run oracle Database 10g Release 2 (10.2.0.1.0) on window vista ,any compatibility issues ? If yes....Pls show me the way. Thanks,

  • OBIEE 11.1.1.6 Scheduler Server fails to start

    When the server is rebooted we often have failures in start up of the scheduler server in bipublisher. It is always connect to a MBEAN failure. During operations when it does come up we see a lot of error messages about MBEAN errors as well. I would