Open Tiff, rotate, resize and save as JPEG (using JAI)

I 'm having a hard time getting my arms around the JAI classes to perform
this transform. I've looked at the tutorial and api, etc and did not get
very far.
I have the code to open the TIFF, and save as a JPEG. My question is how to
go from there to do the manipulations (rotate, resize)?
If anyone knows how to do this with JAI classes, please let me know.
Thanks,
Bill Pfeiffer
My code:
try
SeekableStream input = new FileSeekableStream("C:\\S1000000.TIF");
FileOutputStream output = new FileOutputStream
("C:\\S1000000.jpg");
TIFFDecodeParam TIFFparam = new TIFFDecodeParam();
ImageDecoder decoder = ImageCodec.createImageDecoder("tiff",
input ,TIFFparam);
JPEGEncodeParam JPEGparam = new
JPEGEncodeParam();
ImageEncoder encoder = ImageCodec.createImageEncoder
("jpeg",output,JPEGparam);
RenderedImage ri = decoder.decodeAsRenderedImage();
encoder.encode(ri);
input.close();
output.close();
catch (IOException e)
e.printStackTrace();

For Rotation....
1) add the following function to your code.
private RenderedImage rotate(int degrees, RenderedImage src, Interpolation interpRotate) {          
                         try {               
                                   float radians = (float)(degrees * (Math.PI/180.0F));
                                   ParameterBlock pb = new ParameterBlock();
                                   pb.addSource(src);
                                   pb.add(0.0F);
                                   pb.add(0.0F);
                                   pb.add(radians);
                                   pb.add(interpRotate);
                                   src = (RenderedImage)JAI.create("rotate", pb, null);
                                   pb = new ParameterBlock();
                                   pb.addSource(src);
                                   pb.add((float)-(src.getMinX()));
                                   pb.add((float)-(src.getMinY()));
                                   pb.add(interpRotate);
                                   return (RenderedImage)JAI.create("translate", pb, null);
                         }catch (Exception e) {               
                                   return src;
2. call this function before the "encoder.encode(ri);" line in your code. I pass "new InterpolationBilinear()" for the interpolation parameter of the function.
For scaling...
1) add the following lines to your code after or before you rotate the image.
ParameterBlock pb = new ParameterBlock();
pb.addSource(ri);
pb.add(1.1F); //play with these 4 lines to make the image bigger or smaller (1.0F is actual size)
pb.add(1.1F);
pb.add(0.0F);               
pb.add(0.0F);               
pb.add(new InterpolationNearest() );
t = (RenderedImage) JAI.create("scale",pb,null);
hope this helps. Just play with it a bit. You'll get it.

Similar Messages

  • "Open . . ." and "Save as . . ." crash applications

    Ever since the latest round of software updates were installed on my computer a couple weeks ago (a security update and one other update) I've had a problem with the "Open . . ." and "Save As . . ." options in any application. The problem seems to occur anytime an application tries to open a window with a file browser (Finder windows appear to be unaffected). The program hangs for a few seconds and then crashes. I've sent a couple of crash reports to Apple in the past few days.
    The crashes are reported in system.log. They all include the following:
    kernel[0]: disk0s3: I/O error.
    Furthermore, when I look at the application-specific crash logs I find the following in all of them:
    Exception: EXCBADACCESS (0x0001)
    Code[0]: 0x0000000a
    Code[1]: 0x93e20fa4
    If anyone can offer any help it would be greatly appreciated. Thanks!

    Vartiala wrote:
    Is it possible that PSE keeps in mind that I "always" like to open from "A" and save into "B",
    without changing everytime the directory name?
    No.
    The FileOpen and FileSave dialog windows are Windows system dialog windows.  The remembered last-used directory is common to both.
    Ken

  • How do I edit RAW photos and save as jpeg?

    HI! I have some RAW photos that I want to edit and save as jpeg. Will the edits compromise the file and how do I then save these edited files as jpegs and will that compromise the files? THANKS!

    What do you mean by “Will my files be compromised“?
    When you edit a photo with iPhoto you’re Original file is preserved exactly as it is, there are no changes made to it whatever.
    will I be able to make a readable disc?
    Why not? But what do you mean by “readable” Readable by who?
    Regards
    TD

  • What steps do I take to edit raw files and save for web use, such as Instagram, Facebook, Websites, and emailing?

    What Steps do I take to edit raw files and save for web use, such as Instagram, Facebook, Websites, and emailing?

    When you open a raw file it will open in Adobe camera raw. That is where you can do most of the editing. Then it will be placed inside Photoshop where you can do more if needed.
    Now you can use the save for web dialog to export your image as a png or jpg to use on those sites.

  • How do you create and save icc profiles using photoshop?

    How do you create and save icc profiles using photoshop?

    You don't. Color profiles require specific measurement hardware and software.
    Mylenium

  • Acrobat reader installed fine, but opens for five seconds and then closes. Using Windows 7 and mcafe

    Acrobat reader installed fine, but opens for five seconds and then closes. Using Windows 7 and McAfee on a Dell laptop.

    You can try using Windows Explorer to navigate to C:\Program Files (x86)\Adobe\Reader 11.0\Reader, then double-click on Eula.exe and accept the license agreement

  • Batch Process Export As and Save As JPEG Question?

    What is the method for creating scaled JPEGs from PNG files with batch processing (File | Batch Process...)?
    Application environment: Fireworks CS4.
    Using History panel, I manually captured instructions
    Modify | Transform | Numeric Transform (13%)
    Modify | Canvas | Fit Canvas
    File | Save As (JPEG)
    History panel's saved JavaScript file script:
    fw.getDocumentDOM().scaleSelection(0.11999999731779099, 0.11999999731779099, "autoTrimImages transformAttributes");
    fw.getDocumentDOM().setDocumentCanvasSizeToDocumentExtents(true);
    fw.saveDocumentAs(null, true);
    Running this sequence as a batch job requires manually selecting JPEG and "okaying"
    CS4 documentation for saveDocumentAs is defined with different argument list: fw.saveDocumentAs(document) .  CS4 documentation also has: fw.exportDocumentAs(document, fileURL, exportOptions) to export JPEG (80% quality).  CS4 feature File | Image Preview... | Export does not create a history record for guidance.  I cannot find an example of either instruction save a file to a local folder in JPEG format.  My objective is to add an additional batch step Rename (prefix) for the JPEG output, and script this a a batch process.

    Joyce,
    Thank you.  Your suggestion helped clear my mental log jam.
    Fireworks batch scripting seems to work in reverse.
    Using "Batch Process..." scripting interface 'Export' (as JPEG) option first, 'Rename' (add Prefix) option second, and then follow these by using the history panel's 2 previously saved steps (Numeric Transform, Fit Canvas), batch process now works.  PNG file (list) is saved in targeted folder as a reduced scale JPEG with a prefixed file name.
    Batch Process allows the entire newly defined command sequence to be saved (script.js).  Placing this (renamed) file into Firework's batch look-up directory for scripts (C:\Documents and Settings\account_name\Application Data\Adobe\Fireworks CS4\Commands) does not work.  The file name does not display in "Batch Process" window "Batch options:" Commands drop-down list.
    Batch Process only works by recreating the above steps each use.
    The new (JavaScript) file is 26 KB.  Is script file size limited in Fireworks "Batch options:" feature?

  • HT3775 How can I open AVI video formats and save them in a more user friendly version?

    I am trying to open and save videos which are apparently saved in AVI format. I can't seem to be able to do either. Anyone has any idea how? Thanks!

    http://perian.org
    Still works though no longer supported.
    http://support.apple.com/kb/dl923
    The "other" version of QuickTime Player.

  • Error Log Contains Path To PSD, I need to open each one listed and SAVE AS with Maximum Compatibility

    Hi,
    I am looking to create a script that pulls the path of the listed PSD from the attached Error Log file.
    The files could not be read. Please re-open the files in Photoshop and save them with the ‘Maximize Compatibility’ preference enabled. (20)
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Sheraton Cypress\PSDs\Sheraton Cypress Court Restaurant.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Sheraton Cypress\PSDs\Sheraton Cypress Rock Garden.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Sheraton Cypress\PSDs\Sheraton Link.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Sheraton Cypress\PSDs\Sheraton Cypress Court Area.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Sheraton Cypress\PSDs\SheratonCypress_Guestroom.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\PSDS\Ballroom.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\PSDS\DiningArea.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\PSDS\Lobby.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\PSDS\Pool.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\PSDS\Meeting Space.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\PSDS\Fitness.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_Guestbathroom.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_GuestSuite.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\FP_London_BusinessCenter.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_GuestroomBathroomTwo.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_GuestroomBathroom.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_GuestSuite_Desk.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_Guestroom.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Four Points London_Guestroom_Double.psd
        \\WDMYCLOUDEX4\imageArchive\Brandon Barre\Bradon\Four Points London\PSD\Untitled1.psd
    The text above was created when the PSD was saved with Maximum Compatibilyt turned off and Lightroom will not Import them.
    I am looking for guidance or someone to create it as I am willing to pay for it that references the text file, each line opening the file in Photoshop and Saving As in same place with Maximize Compatibility and done sequentially.
    Thank you kindly,
    Thomas

    Something to get you started:
    var inputFolderPath = "/path/to/folder",
        outputFolderPath = "/path/to/other/folder",
        templatePath = "/path/to/template.indd",
        inputFolder = new Folder(folderPath),
        outputFolder = new Folder(outputFolderPath),
        template = new File(tempatePath),
        files = inputFolder.getFiles(),
        file, fileString, doc, idName, i, l;
    outputFolder.create();
    for (i = 0, l = files.length; i < l; i++) {
        file = file.open('r');
        idName = file.displayName.replace(/\.[^\/.]+$/, '') + ".indd";
        fileString = file.read();
        file.close();
        doc = app.open(template);
        doYourStuff(doc, fileString);
        doc.save(outputFolder + "/" + idName);
        doc.close();
    This would name the versioned InDesign files the same as the input text file but with the ".indd" extension. You might need to consider filtering the files in the getFiles() call, if you have filetypes in your input folder you don't want to process. It's clearer to just re- open the template file on disk, rather than reverting, and amounts to the same thing.
    Jeff

  • SDK Code for bulk opening of Webi reports and Save

    Hi,
    Is it possible to bulk open webi reports using SDK and save it again.
    Thanks,
    Chandra

    Hi Chandra,
    No, This script is for only opening the webi document & saves it back to enterprise without any processing.
    If your webi document have the refresh on open & last prompt value selected properties checked then you don't have to modify the code.
    If you want to handle the prompt as well, then you have to modify the code & write the application flow like below:-
    1. Logon to enterprise.
    2. get infostore service.
    3. get all the webi documents into infoobjects collection
    4. get engines services.
    5. load document instance.
    6. clear the prompt values & set it with new value.
    7. saves the report back to enterprise.
    The 6th point is mossing from the script. You can add that piece of code in the attached script also you can take help from the sample codes & Developer guide & API references.
    Thanks,
    Shailendra

  • To export pivot table from excel and save as picture using powershell

    I am trying to automate my work by attaching an excel file to email and send it across using powershell . But also, I want to paste the screenshot of  pivot table to my email body .
    One way to do it is to save only the pivot table as picture format like jpeg or png , then attach this picture to the email body .
    I am looking for an powershell script which will save my pivot table as picture format . I am using powershell V1.0
    please help .

    I'm not familiar with PowerShell script, we usually use VBA script within excel.
    The following article describes how to export Excel Range to a Picture File and attach it as the email body by VBA code, it might not be the answer you are looking for, but hope it will give you some inspirations.
    http://www.jpsoftwaretech.com/export-excel-range-to-a-picture-file/
    Also you can post your question to PowerShell forum to get better support.
    Best Regards,
    Wind Zhang

  • How to Create Dynamic button at runtime and save it by using c#?

    Hi All,
    Can someone please provide me code to create button dynamically at runtime and save it permanently?
    Your quick help is appreciable.
    regards,
    Sourabh

    You cant add controls to the visual tree a runtime which persist beyond the lifetime of the application.  You will have to persist an indicator to your program which tells it to add the control.  Adding a control is as simple as initializing
    it and adding it to a parent already on the tree.  Controls can be created programmatically or using the XamlReader.Load static method.  You can find XamReader.Load in Windows.UI.Xaml.Markup in windows 8.1, Windows 8.1/Windows Phone unified
    projects.  For old windows phone ad just Silverlight I believe it is in System.Windows.Markup.
    Hope this helps.

  • Design and save workflow diagrams using flex

    Hi,
    I am new to flex..I need to design a workflow diagrams using flex and save the information..Could you please help me on this..
    Actually what exactly i want is..
    In my project we have some jobs..Job is bunch of scripts..These jobs will run in different hosts(Server).In my project we have a provision to run these jobs in order in different hosts.But not for running the scripts in perticular sequence.
    For example::
    We have a,b,c,d,e,f jobs..
    1) these jobs run in order if we select one check box.This provision is there.Order means after a runs b should run.after b is done c should run and so on..
    2) there is another senario like.
       After a job runs b,c should run parallel and these 2 are done d shold run..after it is done e,f,g shold run paralell..some thing like this..This is a sequence of scripts running in different hosts..For this we nned to desing a UI like work flow diagram.
         In UI we show all jobs in data grid and user will drag the jobs and keep it an area and he connects all the jobs with some lines with arrow(to identify).There he should conncects the jobs in which sequence he wants to run the jobs.
      For this need to design a diagram and save the data in the UI.From UI we have to capture the sequence of jobs and store the sequence in db..
    Colud you plz provide me soltion for this..I am getting how to draw a flow diagram using flex and capture the sequence from UI and store the data in DB..
    Please help me out in this issue..
    Thanks in advance...

    I am trying to create an image file with flex and want to save it only in  a perticular directory ie., user should not be given any option to choose the location.Air application uses resolvePath where we can specify the path but donno how this can be achieved for a web-based application.
    Is there any workaround for this?
    Thanks.

  • I have an email attachment that I would like to be able to access when NOTconnected.  I found one suggestion that I should open the attachemtn iniBooks and save it there.  Unfortunately, I have no idea how to do that.

    I am trying to store an email attachment (an Excel spreadsheet) somewhere on my iPhone 5 to be able to access it easily in the future.  I do not need the ability to work on it, just to access it, although it would be convenient if i could load updated versions over it on a regular basis.  The spreadsheet was created in Excel on a laptop with Win 7.  I read one posting that said I should save the document to iBooks and then could open it whenever I wanted.  The same posting refered to something in the upper right corner of the attachment that enabled me to save it to iBooks.  Unfortunately, there is no such option showing when I looked at the file, which I did email to myself.  I was able to open the attachment, but can't get beyond this point.  My tech ability doesn't go much beyond being able to power up my phone, so I need a really simple solution, if one exists.

    First of all, Excel file can't save to iBook.  (iBook only can view PDF files). That's why you don't see it in "open in" options.  In order for you to save excel, you will need a third party app like Numbers, Office2.  There are a few free apps that can use to view.  I used Office2 from Byte2, because I can not only store and view later, I can do some edit too.  Especially when you want to edit a few numbers and re send them to my office or clients will be very useful for me. 

  • Opening tiff image file and finding pixel values at each point

    I want to open a tiff image file using java.Than i want to find out the pixel values at each point.Also if possible red,green and blue values.
    please mail me answer or code if possible on mail id:
    [email protected]

    Use Java Advanced Imaging to open the Tiff. There is
    a tutorial on it. Look to the left for tutorials, look
    for JAI, do what it says.
    For getting the pixels, do this:
    Use a PixelGrabber to get pixels in array:
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    pg.grabPixels();
    Use a MouseMotionListner for
    mouseMoved(MouseEvent moueEvent)
    pixel = pixels[mouseEvent.getX() + (mouseEvent.getY()*width)]
    int alpha = (pixel >> 24) & 0xff;
    int red = (pixel >> 16) & 0xff;
    int green = (pixel >> 8) & 0xff;
    int blue = (pixel ) & 0xff;
    Look up the API for MouseMotionListener, PixelGrabber, etc...

Maybe you are looking for

  • Error while uploading a file using ke13 transactoin

    Hi.. We have the following error when uploading a project plan by cost element excel upload using KE13 transaction... There is a z program that calls this ke13 program while uploading. The excel file is split into x files and uploaded.. THe error is:

  • Can't find ringtones

    A few days ago I bought 3 ringtones from the iTunes store. I never set them to any contact or default, figuring I'd do it when I had more time, like today. I have the iTunes receipt that proves I bought them, but I can't find them on either of the de

  • IDOC TO JDBC Erroe Handling

    Hi, All we have to send ZIDOC To ORACLE system. SAP->XI->JDBC(Asy)scenario. Here how we can handle if it is 1. Network failure(System Errors) 2. Business Errors There is no BPM we decided: IDOC data will insert into ORACLE sys uing value mapping (whi

  • Big ploblems in zen micro

    I just got my zen last week. it seems good in every aspect, but the bad signal quality of FM Radio annoyed me a lot, the speed of loading is slower than expected(i've used ipod before and it's quick), and the battery life can't compare with my former

  • SQL Developer debugger/ How to run/step till a variable attains a req. val

    I have a huge while loop. I want the debugger to step/run till a variable attains a particular value inside the loop. i.e "Break when varA='valA'". How can achieve it? Please don't suggest me to step through while "watching" the particular variable.