How do I create a new image composed of a number of smaller images?

Hi,
I'm attempting to work with the assorted image APIs for the first time and am experiencing one main problem with what I'm trying to do. Here's the scenario;
I have an image file (currently a JPEG) which is 320*200 pixels in size, it contains a set of 20*20 images. I want to take such a file and convert it into a new JPG file containing all those 20*20 images but in a different grid, for example a single column.
I'm currently having no problem in working my way through the input file and have created an ArrayList containing one BufferedImage for each 20*20 image. My problem is that I just can't see how to create a new file containing all those images in new grid.
Any help would be much appreciated and FWIW I've included the code I've written so far.
package mkhan.image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
public class ImageTileConvertor {
   // arg 1 = input file
   // arg 2 = output file
   // arg 3 = tile x dimension
   // arg 4 = tile y dimension
   // arg 5 = number of tiles in x dimension
   // arg 6 = number of tiles in y dimension
   public static void main(String[] args) throws IllegalArgumentException,
                                                 IOException {
     if (args.length != 6) {
       System.out.println("Invalid argument list, please supply the following information in the specified order:");
       System.out.println("  - The input file name including full path");
       System.out.println("  - The output file name including full path");
       System.out.println("  - The size of the tile in the x dimension");
       System.out.println("  - The size of the tile in the y dimension");
       System.out.println("  - The number of tiles in the x dimension");
       System.out.println("  - The number of tiles in the y dimension");
     } else {
       ImageTileConvertor imageConvertor = new ImageTileConvertor(args[0], args[1], args[2],
                                                                  args[3], args[4], args[5]);
   * Instance member vars
  private File m_sourceFile = null;
  private File m_outputFile = null;
  private int m_tileSizeX = 0;
  private int m_tileSizeY = 0;
  private int m_numberOfXTiles = 0;
  private int m_numberOfYTiles = 0;
   * Ctor
  public ImageTileConvertor(String sourceFile, String outputFile,
                            String tileSizeX, String tileSizeY,
                            String tilesX, String tilesY) throws IllegalArgumentException,
                                                                 IOException {
    try {
      Integer tileSizeXInt = new Integer(tileSizeX);
      Integer tileSizeYInt = new Integer(tileSizeY);
      Integer tilesXInt = new Integer(tilesX);
      Integer tilesYInt = new Integer(tilesY);
      m_tileSizeX = tileSizeXInt.intValue();
      m_tileSizeY = tileSizeYInt.intValue();
      m_numberOfXTiles = tilesXInt.intValue() - 1;
      m_numberOfYTiles = tilesYInt.intValue() - 1; // convert to zero base
    } catch (NumberFormatException e) {
      throw new IllegalArgumentException("Tile Sizes must be integers");
    m_sourceFile = new File(sourceFile);
    m_outputFile = new File(outputFile);
    if (!m_sourceFile.exists()) {
      throw new IllegalArgumentException("Input file must exist and be a valid file");
    try {
      translateToTiles();
    } catch (IOException e) {
      throw e;
   * Performs the translation from one format to the other
  private void translateToTiles() throws IOException {
    ImageInputStream imageIn = null;
    BufferedImage bufferedWholeImage = null;
    int imageHeight = 0;
    int imageWidth = 0;
    int currentX = 0;
    int currentY = 0;
    ArrayList imageList = new ArrayList();
    try {
      imageIn = ImageIO.createImageInputStream(m_sourceFile);
      bufferedWholeImage = ImageIO.read(imageIn);
      if (bufferedWholeImage != null) {
        imageHeight = bufferedWholeImage.getHeight();
        imageWidth = bufferedWholeImage.getWidth();
        if (((m_tileSizeX * m_numberOfXTiles) > imageWidth) || ((m_tileSizeY * m_numberOfYTiles) > imageHeight)) {
          throw new IOException("Specified Tile Size is larger then image");
        } else {
          // Process each tile, work in columns
          for (int i=0; i <= m_numberOfXTiles; i++) {
            for (int j=0; j <= m_numberOfYTiles; j++) {
              currentX = i * m_tileSizeX;
              currentY = j * m_tileSizeY;
              createTiledImage(imageList, bufferedWholeImage, currentX, currentY);
        createOutputTiles(imageList);
      } else {
        throw new IOException("Unable to identify source image format");
    } catch (IOException e) {
      throw e;
  private void createTiledImage(ArrayList listOfImages, BufferedImage wholeImage,
                                int xPosition, int yPosition) {
    BufferedImage bufferedTileImage = wholeImage.getSubimage(xPosition, yPosition, m_tileSizeX, m_tileSizeY);
    listOfImages.add(bufferedTileImage);
  private void createOutputTiles(ArrayList imageList) throws IOException {
    ImageOutputStream out = ImageIO.createImageOutputStream(m_outputFile);
    Iterator iterator = imageList.iterator();
    // This doesn't work at the moment, it appears to output all the images but the end file only seems to contain the first small image
    while (iterator.hasNext()) {
      BufferedImage bi = (BufferedImage)iterator.next();
      ImageIO.write(bi, "JPG", out);
      System.out.println(out1.getStreamPosition());
    out.close();
    // This is another attempt in which I can see how to populate a Graphics object with a small sample of the images
    // Although I'm not sure how to output this to anywhere in order to see if it works - can this approach output to a file?
    BufferedImage singleTile = (BufferedImage)imageList.get(0);
    // Now populate the image with the tiles
    Graphics gr = singleTile.createGraphics();
    gr.drawImage(singleTile, 0, 0, Color.BLACK, null);
    singleTile = (BufferedImage)imageList.get(1);
    gr.drawImage(singleTile, 0, 20, Color.BLACK, null);
}Thanks,
Matt

Construct a new BufferedImage whose width is the width of a tile, and whose height is the height of a tile times the number of tiles.BufferedImage colImg = new BufferedImage(m_tileSizeX,
                                         m_tileSizeY * m_numberOfXTiles * m_numberOfYTiles,
                                         BufferedImage.TYPE_INT_ARGB);Now write the tiles onto it.Iterator it = imageList.iterator();
int columnYPos = 0;
Graphics g = colImg.getGraphics();
while (it.hasNext())
    g.drawImage((Image)it.next(), 0, columnYPos, null);
    columnYPos += m_tileSizeY;
}Now save your image.*******************************************************************************
Answer provided by Friends of the Water Cooler. Please inform forum admin via the
'Discuss the JDC Web Site' forum that off-topic threads should be supported.

Similar Messages

  • How do I create a new encrypted image

    Hello all,
    Tried this several times via disk utility.
    Any image created can simply be opened without me being asked for any password!!
    Can someone give me simple step by step instructions on how to successfully create a new encrypted disk  image.
    Many thanks in advance,
    Mark.

    Try How to create a password-protected (encrypted) disk image

  • How do I create a new frame using Flash CS5 on a Mac so I can add more pictures to my website?

    I have what I hope is a fairly straight forward question that I hope you can answer if you write code with a Mac or are at least familiar with the process on a Mac?  The person I have been working with to create my photography website uses a PC.  Here is the problem.  I am trying to use my Mac in order to create frames so that I can add 5 more images to a portfolio that presently has 15 images.  The code is in an index.fla file.  If I want to create a new frame in the index.fla, let's say LOAD CODE 381 and want to use the same text that is already present in LOAD CODE 380 but with a few edits, I have no trouble going to the Action-Movie Clip and finding LOAD CODE 380 in the left hand column.  The problem is, on a Mac, how do I create frame LOAD CODE 381 and then how do I copy and paste the text from LOAD CODE 380 into LOAD CODE 381?  It looks like on a PC one can open LOAD CODE 380 in the Action-Movie Clip, highlight the text then right click on the red rectangular box in the timeline.  By doing so (on a PC) one sees a drop down menu that gives the option to "copy key frame".  What is the equivalent of the "copy key frame" on a Mac?  I can see where on the Mac you can go to Edit >copy.  Is this the equivalent of "copy key frame" on a PC?  If so, once I "copy" the text how do I create the new LOAD CODE 381 so that I can paste the text into the new frame?
    I WOULD BE EXTREMELY GRATEFUL TO ANYONE WITH THE ANSWER TO THIS QUESTION!  THANK YOU!!!!!

    Sorry not to be more clear.  It is a name assigned to one of the 
    frames by the person who originally designed the website and is shown 
    in the list of about 150 action frames that were created in this 
    particular fla document.  This "list" comes up in the left hand column 
    of the Action-Frame box. When I click on Load Code 380 which is half 
    way down the column of frames, the following text comes up on the 
    large screen to the right of the column of 130 frames.
    IMAGE.gotoAndPlay("start");
    loadVariables("data/series01/15title.txt", "_root.IMAGE.TITLE");
    loadVariables("data/series01/15price.txt", "_root.IMAGE.PRICE");
    loadMovie("data/series01/about.swf", "_root.IMAGE.ABOUT");
    IMAGE.mc_pic.attachMovie("pic","pic",1,)
    IMAGE.mc_picTHUMB.attachMovie("pic","pic",1,)
    This text is what I am trying to transfer to copy then paste into a 
    new frame after which time I want to slightly edit the text.  I am not 
    a programer so I apologize if I am not using all of the correct 
    terminology.
    Thank you again,  Jon

  • 4 of us on 1 Apple ID/icloud acct. How do I create 3 new ID's?

    We have 4 members of our family on one Apple ID, and sharing one Cloud acct. How do I create 3 new ID's?  Our cloud acct is full, and we need our own space! :-)

    One person can keep their devices on the current account.  The others can create new accounts with new IDs, then migrate a copy of the data to the new account.  To do this, first create the new Apple IDs here: https://appleid.apple.com/account.  This will require a verifiable non-Apple email account for each.  Then, to migrate to a new account, start by saving any photo stream photos that you want to keep on the device to the camera roll (unless already there) by opening your my photo stream album, tapping Select, tapping the photos, tap the share icon (box with upward facing arrow), then tapping Save to Camera Roll (or Save Image if it's running iOS 8).  If you are syncing notes with iCloud that you want to keep, you'll need to open each of your notes and email them to yourself so you can later copy and paste the text into new notes created in the new account.  Then go to Settings>iCloud, tap Delete Account (or Sign Out if running iOS 8), choose Keep on My iDevice and provide the password to turn off Find My iDevice when prompted.  (Deleting the account only deletes it from this device, not from iCloud; devices keeping the current account will not be effected by this.)  Then sign back in with one of the new Apple IDs to create the new account and choose Merge to upload the data to the new account.
    Once everyone is on separate accounts, you can each go to iCloud.com and delete the other people's data from your account.

  • How can I create a new Music Library?

    Had to buy new laptop which of course has Vista. The old unit was acting up(I think Windows XP was corrupt), so I saved my Library Files but it looks like the old machine only saved portions not the whole Library. I had approx. 13,000 tunes (35GB) in the LIbrary and all that was saved seems to be 319 tunes. I have all the music on an external HD and only the Library was on the laptop. My question is, how can I create a new Library from the external HD music? Is there a way or am I SOL? Any suggestions and help would be greatly appreciated.

    You need the entire libary on the external, not just media.
    What are the iTunes library files? - http://support.apple.com/kb/HT1660
    More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
    What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
    Where are my iTunes files located? - http://support.apple.com/kb/ht1391
    iTunes 9 [and later]: Understanding iTunes Media Organization - http://support.apple.com/kb/ht3847
    Image of folder structure and explanation of different iTunes versions (turingtest2 post) - https://discussions.apple.com/message/13025536 and https://discussions.apple.com/message/17457605
    Once you get a complete iTunes folder on the external drive, start iTunes with the option/alt key held down and select the iTunes Library.itl file on the external drive.  You will also need to do this with your main computer or the libraries will become unsynchronized.
    Alternatively you can make a separate library using the same media on the second computer. Start as you have been doing, let iTunes create a new, blank library file which will be on hte internal drive, set the media folder location in preferences to be the one on the external drive, then add the files to the new iTunes library. Unless you are a super-organized individual, or you don't care if your libraries do not have the same content, you are better off using a single library file that is on the external, not setting up separate library files.

  • How do I create a "New User"

    In my prior post of yesterday, "How do I password protect / lock an album, it was recommended to me to create a new user, then move the desired photos from the current library (current user) to the new library within the new user. Sounds like a good idea, but how do I do it? I'm a bit of a novice. Can someone walk me through the process?
    1. How do I create a new user?
    2. How do I transfer the selected photos in my current library to the new library in my new user name?
    Thanks,
    HDP

    Hi there,
    I think PhillyPhan will post back in your other thread and explain the process...
    But to give you my 2 cents, I would opt to create another iPhoto Library folder that contains the images you do not want to share and keep as private as possible.
    By using this: hold down OPTION key and open iPhoto, a dialog will open, Quit - Create - Choose, just create another library in any part of your HD or even on an external HD under any name or even inside another folder. Once created you can import the photos you want to keep away from the general public. You can go back and forth between libraries by using the same option key etc. iPhoto will open automatically to the last library you opened. So, you can hide the library anywhere you wish on your Mac HD or external, and alot of people don't know the Option key / open iPhoto > choose library function.
    The reasons I would choose to do it this way, someone would need to know you have another library and where the library is located in order to view the images.
    Importing the images will take a bit of work, post back if interested or have any other questions...
    Rick
    iMac G5 iSight 20" - 30G iPOD & Hot Pink Nano 4G - WD 500G FW - Mac OS X (10.4.8) - HP Pav 15" WS and Toshiba Sat 17" WS LP's - Canon 20D & A620 Kodak P880

  • How do I create a new Style that can be applied to an object?

    Under the Assets menu there is a tab called “Styles”.  My question is how do I create a new Style that I can apply to an object???  A link to a tutorial or something like that would be useful because I can’t find anything!!!    Thanks in advance for helping me eliminate this frustration!!! 

    KomputerMan.com wrote:
    What I want to do is create a library of styles that are basically pictures of various wood types.
    There are a couple of approaches you could try.
    Clipping paths
    1. Draw the part shape as a closed path.
    2. Position the image of woodgrain above or below the shape where you want it positioned.
    3. Cut
    4. Select the closed path.
    5. Paste Inside.
    See: Using FreeHand MX > Contents > Working with Objects > Working with clipping paths
    Tiled fills
    1. Use autotrace to trace the image of the woodgrain, using plenty of colors.
    Using FreeHand MX > Contents > Using Imported Artwork > Tracing bitmaps > Tracing an image
    2. Group the traced paths (but not the image) and create a tiled fill,
    Using FreeHand MX > Contents > Using Strokes and Fills > Applying attributes to fills > Using tiled fill attributes
    3. Make a style from a tile-filled object
    4. Apply the style to other objects.
    Judy Arndt

  • How do I create a new lens profile?

    How do I creat a new lens profile for a Canon EF135mm f/2 and EF200 f/2.8 in lightroom 3.3?

    Hi Simon,
    Thanks for your reply.   I figured it out, I  downloaded the new version of Raw 6.3 and now I have the lens profile and others  such as crop constraint and
    chromatic abrerrations.  I was looking for these items in Photoshop Raw
    Thanks,
    Aideen
    If I understand you correctly, you found and downloaded a lens profile that matches your camera and lens, and you don't see the profile in LR?
    1. Make sure that you relaunch LR after you downloaded the lens profiles.
    2. The type of lens profiles (raw or non-raw) matches your image type (raw or non-raw). Namely you can only apply raw lens profiles to raw image files and vice versa for the non-raw profiles.
    -Simon
    >

  • TS2756 How can i create a new usb connection (service)  on my iMac for sharing internet from my iPhone5 ( i seem have to deleted it )

    How can i create a new usb connection (service)  on my iMac for sharing internet from my iPhone5 ( i seem have to deleted it )
    i know its not a problem whit my carrier o data plan or sharing preferences on the ipone because when i use it un my laptop it works perfectly through
    the usb and even works on the Imac through wifi and bluethood tethering but NOT through usb!!.
    the problem is that trying to make it work i deleted the "profile" usb iphone on the network prefereces panel. Now i only have 3 options: ethernet / wifi / bluetooth
    but not the usb iPhone i used to have.
    And when i try to add a new one i dont get a USB option.
    can some one help me please??
    this is how it looks (after the bluetooth PAN i used to have USB iPhone option)

    The question would be more appropriate in the Mac forums as it is not really related to the iPhone.

  • How do I create a new icloud email address for my apple id?

    Hi there
    How do I create a new icloud email address for my apple id? My original email address is associated with my previous employers.
    When I send email from my Macbook, it seems as if I still work there, which is a problem.
    I would like to use the email address that I created for my iPad.
    When I login with my appleid (for my macbook) I keep getting the old company one, not the new one.
    Is there any way of resolving this? I
    Thanks
    Kelvin

    Welcome to the Apple Community.
    Providing you aren't trying to change you Apple iCloud email address you can make changes at My Apple ID

  • How can I create a new ring tone for my iPhone 4?

    How can I create a new ring tone for my iPhone 4? I followed the Garage Band process and ended up with the ring tone I want as a AAC audio file. It got stored in my iTunes a a song rather than a ring tone. How do I make it a ring tone vs. a song? I tried dragging it t the Ring Tone category at the bottom of the ITunes list, but it won't alloow me to move it?

    There's also an easy to use Applescript over at Doug's Applescripts for iTunes. It automates the whole thing. All you do is set the start and stop time on a file in iTuens and run the script. It will do everything else.
    Make Ringable v1.1
    http://dougscripts.com/475

  • How to i create a new itunes account for my old iphone so i can transfer data to new iphone, since my daughters new iphone is now linked to my acc and she ends up with all my apps and contacts etc

    My daughter has previously had an ipod which was linked to my itunes iphone account.
    she now has a new iphone and has linked this to that account and now she receives all my contacts apps etc when she syncs her account.
    How do i create a new itunes account for my old iphone so that i can transfer data to my new iphone and keep the two seperate so that when she deletes all my contacts and apps and then syncs her phone again we can still be compatible.

    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • I have an iPad and and iPhone. They share an iCloud and I want separate iCloud accounts. How do I create a new account without losing any information? I want to keep the original account on one device.

    I have an iPad and an iPhone that share an iCloud account. I didn't realize when I got my iPad last year that when I signed up the iCloud on the device that it would share and use 5g of iCloud between the both of them. How do I unsync them and have two separate iCloud accounts? I don't care about sharing between them. When my kids put games on my iPad, I don't want them going on my phone. How do I create a new iCloud without losing any info on the other device?

    Hi sugaliko,
    You may need to set up your BlueTooth connection to the keyboard again. Use the steps in this article for guidance -
    iOS: Third-party Bluetooth accessories
    http://support.apple.com/kb/HT1664
    Thanks for using Apple Support Communities.
    Best,
    Brett L

  • I have itunes on my computer but its my wifes account. how do i create a new account for me?

    i have itunes on my computer but its my wifes account. how do i create a new account?

    I have the same problem,,,any help please ? thnx

  • I am trying to install a Canon Pixma MG8220 which requires my Airport Extreme password. I do no know it. I then  went to default Airport settings and renamed my network, but Airport required my password. How do I create a new password?

    How do I create a new password for my Airport Extreme if I do not know the old password?

    If you have the Mac that you used to configure the AirPort Extreme originally, you may be able to retrieve the password from KeyChain Access.
    See this User Tip from forum expert Tesserax:
                     AirPort - Regain Access from Forgotten Passwords
    If still no luck, you can reset the passwords again. Pay very close attention to the information about a Soft Reset in this Apple support document:
    Resetting an AirPort Base Station or Time Capsule FAQ

Maybe you are looking for

  • OTM - At the time of issue handling status is updated each time

    Hello, While handling the issue till the time it get fixed, each time the status gets updated but not maintaining the status history along with the description and solution. We need to figure out the status history .

  • EFI MacBook 4.1 to fun Yosemite

    Hello, On my iMac 7.1 mid 2007 i succeded to install Yosemite. I would like to do the same on my MacBook 4.1. I need the EFI of the MacBook 5.1 last generation. Can you help me to install This EFI? best regrad. Marc

  • Can you share project plans with customers

    if I want to give a customer a MSP file with a plan in it; but I want them only to see the columns I want: no rates; no enterprise project fields (namely profit/GM) - how do I save Trying to stop the swap to Salesforce - but the errors keep a coming

  • Keyboard doesn't appear when trying to type into Numbers cell

    I'm having a strange problem trying to use the latest Numbers app on my iPad 2,. I opened a new spreadsheet but the virtual keyboard doesn't appear when I try to enter text in a cell.  I can only get the "Paste" option.  When I hit that, it enters te

  • Configure IPv6 ACL Extensions for Hop by Hop Filtering

    I have IPv6 ACL questions and concerns.  The following code is an example: ipv6  access-list inbound-to-enclave      remark block IPv6 DO Invalid Options       deny 60 any any dest-option-type 5      deny 60 any any dest-option-type 194      deny 60