Join two seperate tiff images

pls help me.
I am new to jai.I have done to split tiff document into seperate -2 tiff docs by pages no. but I have no idea how to add tiff documents into one document.

I got this code while searching
hope it will help you...
import java.io.*;
import java.util.*;
import java.awt.image.*;
import java.awt.image.RenderedImage;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import com.sun.media.jai.codec.*;
public class Multipagetiff {
public static PlanarImage readAsPlanarImage(String filename) {
return JAI.create("fileload", filename);
public static void saveAsMultipageTIFF(RenderedImage[] image, String file )
throws java.io.IOException{
String filename = file;
if(!filename.endsWith(".tiff"))filename = new String(file+".tiff");
OutputStream out = new FileOutputStream(filename);
TIFFEncodeParam param = new TIFFEncodeParam();
ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", out, param);
Vector vector = new Vector();
for(int i=1;i<image.length;i++) {
vector.add(image);
param.setExtraImages(vector.iterator());
encoder.encode(image[0]);
out.close();
public void createMultipageTiff(String[] filenames){
RenderedImage image[] = new PlanarImage[filenames.length];
for(int i=0;i<filenames.length;i++) {
image[i] = readAsPlanarImage(filenames[i]);
try {
saveAsMultipageTIFF(image, "multipagetiff");
catch (Exception e) {e.printStackTrace();}
public static void main(String[] args){
Multipagetiff mtiff = new Multipagetiff();
if(args.length <1) {
System.out.println("Enter a image file names");
System.exit(0);
mtiff.createMultipageTiff(args);

Similar Messages

  • Moving two seperate images in an applet

    Hi i am trying to move two seperate images on an applet. these images are two random cards from a pack of playing card, ie king,jack, queen etc..
    i can get both images moving at the same time but i want i want to do is to animate the movement of one image and when it raches a certain point onscreen, the other image moves to a different position onscreen and i should end up with both card images onscreen at different positions.
    here is the code for the part in which the applet draws the image to the graphics object:
    public void run()
            long tm = System.currentTimeMillis();
             while(Thread.currentThread() == t)
                 repaint();
                 try
                     tm += delay;
                     Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
                     //increment frame so that image moves 4 pixels at a time
                     f1 = f1 + 4;
                     f2 = f2 + 5;
                     f3 = f3 + 2;
                     f4 = f4 + 2;
                 catch(InterruptedException e)
                     break;
        public void stop()
            t = null;
        public void update(Graphics g)
            //code that generates 5 random card and animate them onscreen.
            Dimension d = size();
            int w = cards[r1].getWidth(this);
            int h = cards[r1].getHeight(this);
            if(f1 <= 100)
                // Erase the previous image
                g.setColor(getBackground());
                g.fillRect(0, 0, d.width, d.height);
                g.setColor(Color.black);
                g.drawImage(cards[r1], f2, f1, this);  //co ordinates
                if((r1 != r2) && (f1 == 100 ) && (f3 <= 300))
                    g.drawImage(cards[r2], f4, f3, this);  //co ordinates
            //g.drawImage(cards[r2], f4, f3, this);  //co ordinates
        }Has u can see from the above code. all 52 card images are stored in an array. I use a random function to generate a random image from the array, in this case two random images.
    i have used if statements that tell me when to stop the animation of an image and when to start the next image for animation using the f1,f2,f3 etc.. these are used for the co ordinates of the actual images.
    i increment them each time the applet is run from within a Thread.

    Sounds like you just need a little swing(or awt if you're using "old java")
    http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html
    BorderLayout might be useful. Be aware that it can be tricky to switch out swing components and you may need to validate the container.
    Also, be aware that a "Frame"(JFrame) in java are what you would call a window and that a "Panel"(JPanel) in java is basically just an area that contains components, kinda like a <div> or <span> in html.

  • Getting a black image after joining two images

    Hey Guys,
    I have joined two images. In the joined image. i am getting the first image but the second one im getting as a black image. Can you please tell me what is the problem??
    Below is the code:
    w = inv*img[inv].getWidth(null) + img1.getWidth(null);
         h = Math.max(img[inv].getHeight(null), img1.getHeight(null));
         BufferedImage[] joinedImg = new BufferedImage[lnuInvoiceIndex];
         Graphics2D[] g = new Graphics2D[lnuInvoiceIndex];
    JPEGImageEncoder[] encoder=new JPEGImageEncoder[lnuInvoiceIndex];
         for(int join=0;join<=lnuInvoiceIndex;join++){
    joinedImg[join]=new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    g[join] = joinedImg[join].createGraphics();
    g[join].drawImage((BufferedImage)thumbImage[inv], 0,0, null);
    encoder[join] = JPEGCodec.createJPEGEncoder(response.getOutputStream());
    encoder[join].encode((BufferedImage)joinedImg[join]);
    }

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.swing.*;
    public class JoinImages {
        private JPanel getContent(BufferedImage[] images) {
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(wrap(join(images, 4)), "Before");
            panel.add(wrap(join(images, 1)), "Last");
            panel.add(wrap(join(images, 2)));
            return panel;
        private BufferedImage join(BufferedImage[] images, int rows) {
            int cols = images.length/rows;
            // For all images having the same size.
            int iw = images[0].getWidth();
            int ih = images[0].getHeight();
            int w = cols*iw;
            int h = rows*ih;
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage image = new BufferedImage(w, h, type);
            Graphics2D g2 = image.createGraphics();
            for(int j = 0, index = 0; j < rows; j++) {
                for(int k = 0; k < cols; k++) {
                    int x = k*iw;
                    int y = j*ih;
                    g2.drawImage(images[index++], x, y, null);
            g2.dispose();
            return image;
        private JLabel wrap(BufferedImage image) {
            return new JLabel(new ImageIcon(image),
                              JLabel.CENTER);
        public static void main(String[] args) throws IOException {
            String[] ids = { "-c---", "--g--", "---h-", "----t" };
            BufferedImage[] images = new BufferedImage[ids.length];
            for(int j = 0; j < images.length; j++) {
                String path = "images/geek/geek" + ids[j] + ".gif";
                images[j] = javax.imageio.ImageIO.read(new File(path));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new JoinImages().getContent(images));
            f.pack();
            f.setLocation(200,200);
            f.setVisible(true);
    }Geek images from [Using Swing Components: Examples|http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html].

  • How can I merge two TIFF images in one...?

    I need some help please, I am looking for a way to "resize" black & white single TIFF images.
    The process I need to do is like cutting a small image and paste it over a new blank letter-size image (at 300 dpi), like a template.
    Or better yet, is there a way to do something like this...?
    Open image...
    image.*width* = 2550;
    image.*height* = 3300;
    image.save();Some APIs and topics in the internet do or talk about resizing, but the final images get stretched or shrinked and I need them not to do so at all.
    Also, I do not need to display the images, only to get the TIFF images processed and saved back to a file.
    How can I do this with Java and JAI? Unfortunately I am almost new to this and I don't know how difficult it might be to deal with images.

    If 2550 x 3300 isn't the original aspect ratio of the image, then the image is going to looked streched or shrinked in at least one dimension. There is no way around that. It would be like resizing a 2 pixel by 2 pixel image into a 3 pixel by 6 pixel image. The image would look like it's height shrunk or it's width stretched. Had I resized it to 3 pixels by 3 pixels or 6 pixels by 6 pixels, though, then it wouldn't look shrunken or streched.
    Open image...
    image.*width* = 2550;
    image.*height* = 3300;
    image.save();*1)* To open a TIFF image you can use the javax.swing.ImageIO class. It has these static methods
    read(File input)
    read(ImageInputStream stream)
    read(InputStream input)
    read(URL input) You can use which ever method you want. But first you need to install [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html]. The default ImageReaders that plug themselves into the ImageIO package are BMP, PNG, GIF, and JPEG. JAI-ImageIO will add TIFF, and a few other formats.
    The downside is that if clients want to you use your program on their machine then they to will need to install JAI-ImageIO to read the tiffs. To get around this, you can go to your Java/jdk1.x.x_xx/jre/lib/ext/ folder and copy the jai_imageio.jar file (after you've installed JAI-ImageIO). You can also obtain this jar from any one of the zip files of the [daily builds|https://jai-imageio.dev.java.net/binary-builds.html#Daily_builds]. If you add this jar to your program's classpath and package it together with your program, then clients won't need to install JAI-ImageIO and you'll still be able to read TIFF's. The downside of simply adding the jar to the classpath is that you won't be able to take advantage of a natively accelerated JPEG reader that comes with installing JAI-ImageIO (instead, ImageIO will use the default one).
    *2)* Once you've installed [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html] and used ImageIO.read(...), you'll have a BufferedImage. To resize it you can do the following
    BufferedImage newImage = new BufferedImage(2550,3300,BufferedImage.TYPE_BYTE_BINARY);
    Graphics2D g = newImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(oldImage,0,0,2550,3300,null);
    g.dispose();Here, I simply drew the old image (the one returned by ImageIO.read(...)) onto a new BufferedImage object of the appropriate size. Because you said they were black and white TIFF's, I used BufferedImage.TYPE_BYTE_BINARY, which is a black and white image. If you decide to use one the BufferedImage types that support color, then a 2550x3330 image would require at least 25 megabytes to hold into memory. On the other hand, a binary image of that size will only take up about one meg.
    I specified on the graphics object that I wanted Bilinear Interpolation when scaling. The default is Nearest Neighbor interpolation, which while fast, dosen't look very good. Bilinear offers pretty good results scaling both up or down at fast speeds. Bicubic interpolation is the next step up. If you find the resized image to be subpar, then come back and post. There are a couple of other ways to resize an image.
    Note, however, if 2550 x 3300 is not the same aspect ratio as the the TIFF image you loaded, then the resized image will look shrunk or stretched along one dimension. There is absolutely no way around this no matter what resizing technique you use. You'll need an image whose original dimensions are in a 2550/3300 = .772 ratio if you want the resized image to not look like it's streched (you can crop the opened image if you want).
    *3)* Now we save the "newImage" with the same class we read images with: ImageIO . It has these static methods
    write(RenderedImage im, String formatName, File output)
    write(RenderedImage im, String formatName, ImageOutputStream output)
    write(RenderedImage im, String formatName, OutputStream output)You'll suply the resized BufferedImage as the first parameter, "tiff" as the second parameter and an appropriate output for the third parameter. It's pretty much a one line statement to read or write an image. All in all, the whole thing is about 7 lines of code. Not bad of all.
    Now as for the 300 dpi thing, there is a way to set the dpi in the Image's metadata. I'm pretty good at reading an image's metadata, but I've never really tried writing out my own metadata. I know you can set the dpi, and I have a somewhat vague idea how it might be done, but it's not something I've tried before. I think I'll look more into it.

  • Combining two seperate pagemaker files into one pagemaker file.

    We are having done two seperate pagemaking files in two different systems. We are in need to combine/join these two pagemaker publications into one pagemaker publication. How to do this?

    There's several options.
    1. If the two publications are on different PCs, then create a PDF of each and combine them in Acrobat.
    2.Use the Book utility to combine the files when you print.  They need to be on the same PC.
    3. If the two publications are on the same PC (with all the necessary fonts and images), and the files are small, i.e. no more than a few pages, then open both publications in PM.  Tile the two publications side by side.  Add the required number of new pages to the first document, and have "New page 1" opposite "Page 1" of the second publication.
    With the pointer tool selected in the second publication, click Edit - Select All.  Then quickly drag all the objects acroos to "New Page 1" in the first publication.
    Do the same for the remaining pages - hence the requirement for not having too many pages.
    Use File - Save As to save the first publication with a new filename.  All links to images will be preserved.

  • Can you please help me by saying me how can i join two different picture to make it as one picture.??

    Hi Sir/ Madam,
       My name is Rishav and I am facing some problem with my Photoshop CC. Actually I have a question. If you guys could help me out i will be very obliged. The quest in "Can you please help me by saying me how can i join two different picture to make it as one picture.??"

    Maybe you should post over at
    Photoshop for Beginners
    or start with the "Get Started" section of the Help:
    Photoshop Help | Photoshop Help
    And your question
    Can you please help me by saying me how can i join two different picture to make it as one picture.??
    does not seem particularly specific – do you want to simply combine two images as they are, do you want to clip elements from the one and insert them into the other, …?
    Could you post (lores of) the images and explain what you intend to achieve?

  • Error encountered while reading TIFF image, Image may be damaged of incompatible. Resave the image w

    I am currently running CS3, windows XP, service pack 2, with recent update, 5.03 installed today.
    I just opened a 500 page document not in sections where 90% of the document is a placed PDF.
    The PDFS were placed using a sample Script that came with Indesign, that instructs the PDF to automatically flow each page after another.
    When scrolling through quickly in the pages pallette, I get the follwing error:-
    "Error encountered while reading TIFF image, Image may be damaged of incompatible. Resave the image with different settings and try again."
    I click OK.
    Then I get the following error.....
    " Could not complete request because of database error. The File "ABC.indd" is damaged (Error Code: 3).
    Click OK....
    Then I get the following error....
    Adobe Indesign is shutting down. A serious error was detected. Please restart Indesign to recover work in any unsaved Indesign documents.
    Then I get the error.......
    Indesign.exe has encountered a problem and needs to close. We are sorry for any inconveneince.
    And I have two buttons to click....
    Debug or Close.....
    If I click Debug, it closes Indesign.
    Within this window there is also a window to gather further information....I click it and it tells me...
    "Indesign.exe....Error Signature AppName: indesign.exe AppVer: 5.0.3.662
    ModName: public.dll ModVer: 5.0.3.662 Offset: 0002e19a"
    To view technical inforamtion about the error report, clikc here....
    "Then it creates an error report and tells me where the report is located along with a scrollable window of 0xc0000005 and heap of zeros."
    The report conatains a whole heap of CHECKSUM ERRORS.
    CAN ANYONE PLEASE HELP??
    I had these errors before updating to 5.03 and the patch hasn't rectified anything!!

    Open the .inx file in CS3 (that's what you have, right?) and save as a new .indd.
    I'd also be tempted to open the tiff in Photoshop and do a save as to re-write it.
    Let us know if it helps.
    Storing files on the network leaves you more open tot he risk of file damage during transfer and save operations.
    Peter

  • How to join two MP4 movies with iMovie '11?

    Just after a quick bit of help here.  I'm not a movie making enthusiast so never used iMovie before and never will again most likely.  However I do have 2 mp4 movies about 4 minutes each that I SIMPLY want to join together.
    I've searched and seen reference to dragging the fils into a project then just export as one but for the life of me if import the files I can't seem to find anywhere that provides a view of the two files as thumbnails so I can just drag them to say this one first, this one second.  Join please.  I seem to get streams and streams of individual frames with sliding lines and what not and the best I seem to be able to get is about 4 seconds at a time.  Surely ther MUST be an easy way to just join two movies together without going into advanced frame by frame editing.
    It's not the most intuitive piece of software and I don't have any desire to learn it.  Problem is I am in a **** of rush with this and at the end of a 14 hour image managament day which is making me less than patient with iMovie. 

    QuickTime X can join your two files. Edit menu "Add Clip to End..."

  • Join two ThemeBasedFOI in one

    Hello,
    I am working with the Mapviewer Javascript API and I would like to know if it is possible to join two ThemeBasedFOI in one. I have 2 themebasedfoi each one with one style applied and I need to show both of them as only one.
    Thanks in advance.

    No, not with iPhoto.
    You'll need to use an external editor for the job.
    In order of price here are some suggestions:
    Seashore (free)
    _[The Gimp|http://www.gimp.org/macintosh>_ also free
    Graphic Coverter ($45 approx)
    Acorn ($50 approx)
    [Pixelmator|http://www.pixelmator.com> ($60 approx.)
    Photoshop Elements ($75 approx)
    There are many, many other options. Search on MacUpdate.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Regards
    TD

  • Joining two datasets in Crosstabs

    Hi....I have a requirement in crosstabs...
    I have 3 data sets…. Ds1, ds2, ds3
    Month column comes from all the 3 data sets.
    I have a Category Column which comes from all three datasets…. (category = Mother board,mouse,key board )
    Max sales, Avg sales, Total sales are the columns which comes from ds1, ds2, ds3 respectively..
    Is it possible to achieve this following out put by cross tabs?
    How to join two/three data sets in crosstabs??
    Image below:
    http://i51.tinypic.com/2u9k421.jpg

    The Lookup expressions are used for this. They all use a similar syntax:
    =command(LocalKey, ForeignKey, ForeignValue, "OtherDatasetName")
    This is similar to JOINing tables ON LocalKey=ForiegnKey in Transact-SQL. The expression builder tool will give you some limited help with the 3 Lookup expressions . Visakh's link has more extensive help.
    The Join expression mentioned by Brad is often used in conjunction with the LookupSet and MultiLookup expressions, which return an array of values (ForeignValue) rather than a single value like Lookup. Join will concatenate the elements of an array into
    a string.
    "You will find a fortune, though it will not be the one you seek." -
    Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

  • Trying to join two views that have different column types

    I want to join view1 and view2 on region and city int columns. Need to break apart View1 varchar field into two Int fields and replace any non-numeric values with zeros.
    View1 has a single Region_City field that is VARCHAR. the last record is erroneous. the individual values for Region and City should always be Int. 
    0001-8374
    0222-0034
    3333-0001
    XXA-EEE
    View2 has Region and City as two seperate Int columns (i will seperate with comma just for display)
    Region,City
    1,8374
    222,34
    3333,1
    I want to create two new individual columns in view1 that will have Region and City each as a Int. And for any Region_city that is invalid numeric just use zeros in Region and City.
    I currently have this (in house ParseDelimited sproc), but am having trouble with the invalid numeric values (XXAA-EEE)
    REPLACE(LTRIM(REPLACE(dbo.ParseDelimited (Region_City, '-', 1), '0', ' ')), ' ', '0') as Region,
    REPLACE(LTRIM(REPLACE(dbo.ParseDelimited (Region_City, '-', 2), '0', ' ')), ' ', '0') as City,

    This is a way to do it, by no means the only way, but a way.  (The other way to achieve this would work fine, but would require functions inside functions inside other functions, including repeating at the very least "Patindex('-', RegionCity)"
    a few times.  In this situation, the APPLY statement comes in handy by making it a little easier to read.
    Declare @ExampleTable Table (RegionCity Varchar(99))
    Insert @ExampleTable /* This is just to recreate a test table */
      Select '0001-8374'
      UNION ALL Select '0222-0034'
      UNION ALL Select '3333-0001'
      UNION ALL Select 'XXA-EEE'
      UNION ALL Select 'a really bad error, no numbers or dash at all'
      UNION ALL Select '1-2'
      UNION ALL Select '12345678-98765432'Select RegionCity
        , Cast(  Coalesce( Case When IsNumeric(RegionCode) = 1 then RegionCode else '0000' End, '0000') as Int)  as RegionCode
        , Cast( Coalesce( Case When IsNumeric(CityCode) = 1 then CityCode Else '0000' End, '0000') as Int) as CityCode
      From @ExampleTable
     Outer Apply (Select CharIndex('-', RegionCity) as DashPos) CaDash
     Outer Apply (Select Substring(RegionCity, 1, DashPos - 1) as RegionCode
                        , SubString(RegionCity, DashPos + 1, 99) as CityCode where DashPos > 0) as CA2
    You didn't mention how bad the source data might be, how unpredictable it might be, whether it's always coded exactly as listed.  This way is reasonably flexible.
    EDIT: I used "IsNumeric" in this example.  It's quite an imperfect function, often best avoided, but I used here just because it's probably OK in this example.  
    This is probably better:  "Case When PatIndex('%[^0123456789]%', CityCode) = 0 Then CityCode else 0 End"

  • Tiff images I used in trial version are now blurry in full version of InDesign CS5.5

    I placed two tiff images (visual poems I made) into a file (a manuscript) using a trial version of InDesign CS5.5, and they appeared clear and crisp. Then I bought the full version of InDesign (the Education product as part of Adobe Creative Suite), opened the file, and the two tiff images are completely blurry!
    When I open the tiffs in photoshop and view them as "actual pixels," they are clear and crisp. The resolution is 300. For one image I tried making it a lower resolution, and that didn't help.
    Any ideas? Thanks.

    Hi, I just unchecked the Object Level Display and nothing happened.
    Nothing has changed with the images at all. The only thing that is different is that I created the manuscript in a trial version of the software. Maybe it was an earlier version than the software I purchased? Would that have an effect on the images? I didn't purchase the software directly from the trial version I used. What happened is that the trial version expired. Then a month later or so I bought a new laptop, bought the Creative Suite (Education version, so much cheaper than normal), and then installed the software on the laptop. Then I opened my manuscript using the new software, the CS5.5, and everything was fine except for the images being blurry.
    Is it possible I used a trial version in CS5.0 and then bought CS5.5 and that has something to do with it?
    Thanks for all of your help!!
    I just realized I wasn't logged in & that's why I couldn't reply.
    Message was edited by: patawhateverly

  • How to join two partition

    How can I join two partition on my macintosh from System Ultility

    You'll have to be more specific.
    IF you are talking about two partitions that were set up through Boot Camp Assistant and you want to remove windows and go back to one partition, then simply run Boot Camp Assistant again and choose the option to reunite the partitions.
    IF you are talking about two Mac, HFS+ partitions, there is no easy way to do it. The only solution would be to make a backup (easiest by making an image in Disk Utility), and then repartitioning both drives as one, then restoring from the backup image.
    Partitioning is usually a "final" process that cannot be reversed; boot camp is one exception.

  • Recording on two seperate devices

    I ran into a confusing request. What do you do when you need
    to record a program that runs simultaneously on two seperate
    devices (PCs). Has anyone ever come across this? I'm just trying to
    figure out an effective way of showing both PCs...

    If you're just trying to let the user see the difference,
    another thought is to keep the Windows theme the same on both
    workstations and show the screenshot from Computer A as the slide
    background and show the screenshot from Computer B as a rollover
    image.
    This lets the user do an A/B comparison as many times as it
    takes to get all the differences. You can even add callouts to the
    computer B image to highlight the changed items. Assuming the two
    screens are similar with the same dimensions, it can be very
    effective.

  • Creating blank tiff image

    Hi,
    I want to create a new blank tiff image and attach the existing tiff images to this blank image side by side or columnwise.
    How can i do this using java/JAI ?

    Create the image on the hard disk, compress it or use a tool such as this one to split it into two, and move the compressed or segmented file to the external drive.
    (37541)

Maybe you are looking for