Appending 2 TIF images using Java

Hi All,
I was trying to append 2 TIF image files using the below mentioned code:
File file1 = new File(filename1); //<--OVERLAY
SeekableStream s1 = new FileSeekableStream(file1);
File file2 = new File(filename2); //<--File to be overlaid (1st Page)
SeekableStream s2 = new FileSeekableStream(file2);
TIFFDecodeParam param = null;
ImageDecoder dec1 = ImageCodec.createImageDecoder("tiff", s1, param);
ImageDecoder dec2 = ImageCodec.createImageDecoder("tiff", s2, param);
System.out.println("Number of images in this 1 TIFF: " +dec1.getNumPages());
System.out.println("Number of images in this TIFF: " + dec2.getNumPages());
RenderedImage op1 = (RenderedImage)dec1;//new NullOpImage(dec1.decodeAsRenderedImage(),null,OpImage.OP_IO_BOUND,null);
RenderedImage op2 = (RenderedImage)dec2;//new NullOpImage(dec2.decodeAsRenderedImage(),null,OpImage.OP_IO_BOUND,null);
RenderedImage ri = JAI.create("xor", op1, op2);
//try
String outputFile = "mergedTIFF.tif";
FileOutputStream stream = new FileOutputStream( outputFile );
JAI.create("encode", ri, stream, "TIFF", null);
catch(IOException e){}
Here instead of appending, this code is overlapping both the images. But i want images to be stored in one output file one after the another.
Can you pls provide your valuable solution so that i can proceed with my work.
Thanks
Cheers!!!
Deepak

Hi, you would have better luck in eitehr N2J or JP
http://forum.java.sun.com/forum.jspa?forumID=54
http://forum.java.sun.com/forum.jspa?forumID=31
This forum is for J2ME (Mobile phones)

Similar Messages

  • How to resize image using java imageio

    Hello ,
    I want to know how to resize image using java imageio.
    I dont want to use java awt because i am writing a web application.
    help is very much needed
    thank you.

    Just use an AffineTransform !
    Its much easier

  • How to open and validate the tif images via java?

    Is it possible to open and validating the photoshop images via java. Kindly advise me.
    Thanks for looking into this.
    Maria Prabudass

    I have recently looked at athe code for Image Processor.
    To avoid bailing on errors it uses two techniques.
    1) It turns off all PS error reporting in addition to just turning off dialogs with:     app.displayDialogs = DialogModes.NO;  (it restores the original settings when exiting)
    2) It uses the Javascript construct  Try.....Catch around the basic body of the code so "any" error will not abort the script but just jump to the "Catch" code.
    Hope that is useful

  • How to extract the number from image using java

    Hello every one
    i want to develope a project which can extract the number from image
    that i can use as inter or String or char.
    Is there any API in java which provide this type of facility.
    right now i m using java 5
    thanks in Advance
    Jignesh

    In my project i have a image in that i have a
    co-ordinate (x,y) I am still puzzled as to what you seek. It sounds to me like you have a point (x, y) represented by p. in java it's just p.getX() p.getY()
    i want to convert that cordinate to numeric form,
    i mena i want to use that cordinate in somewhere else
    in project.point.getX() point.getY()
    So need to convert it into numeric form u can called
    it OCR also.OCR is optical character recognition. If I want out and took a picture of the US Declaration of Independence and then wanted the words on the parchement in the picture in text form, then I would run the picture through a software program and it would try to optically recognise what lettering and number were present in the picture. In the end, I would have a text of what is written on the US Declaration of Independence.
    Is that what you want?

  • How to convert JPEG - PNG images using java?

    Hi,
    Has anyone done this before?
    Can you provide me with a sample code or point me to the direction on how this can be done?
    Are there any existing Java technology that supports this?
    Most grateful. Thanks.

    It's should be easy using Java Advanced Imaging (JAI). Try this.
    import javax.media.jai.JAI;
    import javax.media.jai.RenderedOp;
    public class convert {
      static public void main(String[] args) {
        String inName = args[0];
        String outName = args[1];
        RenderedOp source = JAI.create("fileload", inName);
        JAI.create("filestore", source, outName, "PNG", null);
        System.exit(0);
    }

  • Hey need help reading images using java bean

    Hey everyone,
    I will like to read some images from a directory using Java and display it on a JSP page, how do I accomplish this,
    thanks
    KT

    What happen is, I have to display 52 card depending on string concatenation, I have a java file that takes two elements from an array, depending on the two strings concatenation I want to display an image on a jsp page, any ideas on how to accomplish this?

  • Looping thru tif images using OCR

    I have this code below in powershell where I OCR a tif image and save it to a table in sql server.  OCR is only working on the first page and not looping thru the tif image pages.
     Can someone help me with the code to make it loop on my tif image pages ?
     #Functions
    #OCR Function
    #param - imagepath(path the image to ocr)
    Function OCR($imagepath) {
        #create a new modi object
        $modidoc = new-object -comobject modi.document
        $modidoc.create($imagepath)
        try{
            #call the ocr method
            $modidoc.ocr()
            #single page document so I only need the item(0).layout text
            $modidoc.images.item(0).layout.text
        catch{
            #catch the error and go on
            return "Error"
        Finally
            #clean up the object
            $modidoc = ""
    } # end OCR function
    #Function to update the fulltext field in imageskeyvalues table
    #param ID(ID of table)
    function SaveImagesKeyValues($ID, $fulltext)
    $cmd = new-object system.data.sqlclient.sqlcommand
    $cmd.connection = $sqlconnection
    $s = "update dbo.Images_Local set fulltext = '" + ($fulltext.tostring()).replace('''','') + "' where ID = " + $ID.tostring() 
    $cmd.commandtext = $s
    $a = $cmd.executenonquery()
    } #end SaveImagesKeyValues
    #Function to get the list of records to OCR
    function GetImagesKeyValues()
    $sqlda = new-object system.data.sqlclient.sqldataadapter
    $datatable = new-object system.data.dataset
    $sqlcommandselect = new-object system.data.sqlclient.sqlcommand
    $sqlcommandselect.commandtext = 
        "select ID, FullImagePath, fulltext from images_Local  
    where (fulltext is null or fulltext like 'error%')  order by ID "
    #and (fulltext is null or fulltext like 'error%') 
    #"select b.batch_number, b.sequence_number,a.claimnumber, a.potentialamount,a.buyer, b.[document type],b.fulltext, c.imagelastmodified, c.image_path
    #from cip.dbo.cip_mastertable a 
    #inner join imageskeyvalues b on a.claimnumber = substring(b.[claim number],2,6) 
    #inner join images c on b.batch_number = c.batch_number and b.sequence_number = c.sequence_number
    #where (a.buyer = '006' or (a.buyer = '007' and a.potentialamount > 500000))
    #and c.imagelastmodified >= '1/1/13'
    #and b.[document type] = '2'
    #order by c.imagelastmodified"
    $sqlcommandselect.connection = $sqlconnection
    $sqlda.selectcommand = $sqlcommandselect
    #Fill the datatable and store the output in variable otherwise it shows in the output.
    $trap = $sqlda.fill($datatable)
    $datatable.tables[0]
    #end GetImagesKeyValues
    #End Functions
    #Main
    clear
    #set the parent path to the working directory
    $parentpath = "C:\Data\Portugal PRG\Images\Contratos SONAE 08-11\Imdex\"
    #Create new sql connection
    $sqlconnection = new-object system.data.sqlclient.sqlconnection
    #Assign the connectionstring 
    $sqlconnection.connectionstring = "Server=ATL01L20969\SQLEXPRESS;Database=Sonae;integrated security=True"
    #Open the connection
    $sqlconnection.open()
    #get the list of records that need ocr'd
    $imageskeyvalues = getimageskeyvalues
    #iterate through the list 
    foreach ($t in $imageskeyvalues){
    #$completepath = $parentpath + $t.image_path
    $completepath = $t.FullImagePath
    #call the ocr function and put the results in the fulltext property
    $t.fulltext = OCR $completepath
    #give some bread crumbs to monitor the script
    write-host  "Saving " $t.ID 
    #update the database fulltext filed
    Saveimageskeyvalues $t.ID $t.fulltext
    }#end Main

    Hi Abenitez,
    Since the OCR is only working on the first page, as a workaround, please try to spilt the tiff files to multople single files:Tiff Splitter, and then you can use foreach to loop every files.
    Refer to:
    How to split a multipage TIFF file on Windows?
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Append to jar file using java codings

    Hi,
    I have codings which could create jar file and write datas in it. but i need to append datas to existing jar file using java codings.Here i have attached my codings which will write datas to new jar file. when ever i use this my existing contents gets overritten. wat can i add to this to append.
    FileOutputStream stream = new FileOutputStream(archiveFile,true);// archive file is jar file name
         JarOutputStream out = new JarOutputStream(stream, new Manifest());
    JarEntry jarAdd = new JarEntry(tobeJar.getName()); // tobejar is a file to write in jar.
    jarAdd.setTime(tobeJar.lastModified());
                   out.putNextEntry(jarAdd);
                   // Write file to archive
                   FileInputStream in = new FileInputStream(tobeJar);
                   while (true) {
                   int nRead = in.read(buffer, 0, buffer.length);
                   if (nRead <= 0)
                   break;
                   out.write(buffer, 0, nRead);
                   out.closeEntry();
    out.close();

    JarInputStream in = new JarInputStream(new FileInputStream(oldJarName), true); // oldJarName is the JAR that contains all the files we want to keep
    JarOutputStream out = new JarOutputStream(new FileOutputStream(tempJarName)); // this is your "out" variable
    // copy the files from the old JAR to the new, but don't close the new JAR yet
    JarEntry inEnt;
    while ((inEnt = in.getNextJarEntry()) != null) {
      JarEntry outEnt = new JarEntry(inEnt); // copy size, modification time etc.
      byte[] data = inEnt.getSize();
      in.read(data); // read data for this old entry
      in.closeEntry();
      out.putNextEntry(outEnt);
      out.write(data); // copy it to the new entry
      out.closeEntry();
    // now write an entry for the file we want to append - this is the OP's code
    JarEntry jarAdd = new JarEntry(tobeJar.getName()); // tobejar is a file to write in jar.
    jarAdd.setTime(tobeJar.lastModified());
    out.putNextEntry(jarAdd);
    // Write file to archive
    FileInputStream in = new FileInputStream(tobeJar);
    while (true) {
    int nRead = in.read(buffer, 0, buffer.length);
    if (nRead <= 0)
    break;
    out.write(buffer, 0, nRead);
    out.closeEntry();
    // and *now* we close the new JAR file.
    out.close();
    // We then delete the old JAR file...
    new File(oldJarName).delete();
    // ... and rename the new JAR file to use the old one's name.
    new File(tempJarName).renameTo(new File(oldJarName));

  • Hiding the Image in another Image using Java

    Hi all,
    I have to implement the Steganography using Java, i have to get two images and have to hide one image in another , please give me some ideas or sample links where i can explore to implement it...
    Thanks & Regards,
    Justin

    Try the ImageConsumer class. The Image's getSource method returns an ImageProducer that can be linked to the consumer.
    Some images (such as BufferedImage) also provides a Raster, which gives access to its contents through a DataBuffer. I don't know which is the easiest way, though...

  • How to append in excel sheet using Java

    Can anybody help me out in figuring out as how to append in already existing excel sheet using Java.
    I am able to to write in the existing excel sheet using HSSF but is not able to append the data row wise.
    So plz tell me how to do the same.

    Manisha_7 wrote:
    Thnx for the link......No problem.
    but i alsot wanted to know if apart from using poi there is a way to append the data in excel sheet like using JExcel.Don't know. JExcel is also not apart of Java's core API.

  • Uploading .tif images using rstxldmc program

    Hi,
    I have uploaded a .tif image by using 'rstxldmc' program and use that object in sap script.for that im using the code like
    INCLUDE <object name> OBJECT TEXT ID ADRS.
    i can see the logo on my login,but it won't display on other logins.is it require any autorization for that?
    regards,

    May be the image which is stored may not be uploaded properly.
    once u log out and log in again and execute the program, is it appearing in ur client.?
    check it

  • How can i generate BARCODE Images using JAVA Code

    Hello ,
    My requirement is to generate BarCode Images to Print using JAVA Code.
    User will give only
    1) String.as Input Parameter and
    2) Type of Encoding you want to apply on to the String.
    outPut : code should generate Bar Code Images as per the requirements.
    can any one help me out with jars ????? or any link which can provide me start.

    1) I have requriement like generate doc file with
    more than one barcode image on that document.???
    So?
    If your chosen "doc file" format supports inclusion of multiple images there's no problem.
    If it doesn't, choose another format.
    2) I am able to generate .doc file but in which
    format i should open that doc file.????
    The same format you used to create it.
    3) Main thing is how can i put more than one barcode
    image on that doc file????
    That would depend on the file format and the API used to create it.
    is any one faced the same problem or gone through
    same requirement.
    Almost certainly. And they solved it too, given the document I'm looking at right now which is an e-ticket for an airline that has many barcodes and other generated images on it.
    So keep on trying, grasshopper, and you may find enlightenment.

  • How do I overlay n number of  bitmap images using Java.

    Hi All,
    I have a task of creating a composite bitmap or a .gif image from "n" number of bitmap images , so that the resulting composite image will look like as if all those "n" images were placed side by side . How can I achieve this ? Can you point me to some place where I can understand the concepts behind this?

    Create a new BufferedImage with the dimensions of all the images you want combined, then paint all the images into it through the Graphics object you can obtain from the BufferedImage. Then write out the image using the ImageIO class.

  • Print image using java

    Dear All,
    Can any one help me, how to print the image in java.
    Thanks in Advance.

    [http://java.sun.com/products/java-media/2D/index.jsp|http://java.sun.com/products/java-media/2D/index.jsp] will help you . Java 2d also have print api.
    you look at this
    [http://java.sun.com/javase/technologies/desktop/printing/|http://java.sun.com/javase/technologies/desktop/printing/]

  • Programmatically creating VM from already created image using Java

    Hello.
    I am writing a Java program to create VMs from already created VM images. I was able to create through the web portal.
    I am using the API given here http://msdn.microsoft.com/en-us/library/jj157194.aspx
    The request sent is
    <?xml version="1.0" encoding="UTF-8"?>
    <Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Name>mltestdeploy</Name>
    <DeploymentSlot>Production</DeploymentSlot>
    <Label>ZGVwbG95bWVudF9tbHRlc3RkZXBsb3k=</Label>
    <RoleList>
    <Role>
    <RoleName>mltesthost</RoleName>
      <RoleType>PersistentVMRole</RoleType>
    <VMImageName>ml-centos-image</VMImageName>
    </Role>
    </RoleList>
    </Deployment>
    "ml-centos-name" is an existing image with that name and I have used this to create another VM from this image.
    I have already created the required cloud service as required by this API.
    I am getting error 400 with text as "Bad Request". This means some parameter is wrong.
    Any help is very much appreciated.
    -Siva

    Now instead of the VMImageName, I used SourceImageName as given in the example.
    The XML body now looks like
    <Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Name>mltestdeploy</Name>
    <DeploymentSlot>Production</DeploymentSlot>
    <Label>ZGVwbG95bWVudF9tbHRlc3RkZXBsb3k=</Label>
    <RoleList>
    <Role>
    <RoleName>mltesthost</RoleName>
    <RoleType>PersistentVMRole</RoleType>
    <ConfigurationSets>
    <ConfigurationSet i:type="LinuxProvisioningConfigurationSet">
    <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
    <HostName>mltesthost</HostName>
    <UserName>mladmin</UserName>
    <UserPassword>password</UserPassword>
    <DisableSshPasswordAuthentication>false</DisableSshPasswordAuthentication>
    </ConfigurationSet>
    </ConfigurationSets>
    <OSVirtualHardDisk>
    <MediaLink>http://portalvhds7dplkth082kmh.blob.core.windows.net/vhds/1v5wpayu.pwl201404160535060424.vhd</MediaLink>
    <SourceImageName>ml-centos-image</SourceImageName>
    </OSVirtualHardDisk>
    </Role>
    </RoleList>
    </Deployment>
    Even now I get the same 'Bad Request' error.
    Is there any way to find out which element is causing this Bad Request error? Thanks

Maybe you are looking for