Downgrading Image Resolution Using JAI

I am interested in downgrading the resolution of TIFF images that I am inserting into a PDF to reduce the document's file size. The TIFF images are either CCITT G4 bitonal or JPEG RGB. What would be the best approach to doing this using JAI?
I appreciate any suggestions.
Youssef Eldakar
Bibliotheca Alexandrina

Youssef
The following code will load a TIFF image (or JPEG or some other formats that I can't remember) into a PlanarImage object and then rescale it according to the scale factors and then save as a TIFF.
For example if you wanted to change a 320 x 240 image to a 160 x 120 use xScaleFactor and yScaleFactor of 0.5.
  public static PlanarImage rescale(String inputFilename, String outputFilename, float xScaleFactor, float yScaleFactor)
        // load the image from the file
        PlanarImage image = JAI.create("fileload", inputFilename);
        ParameterBlock rescaleParameters = new ParameterBlock();
        rescaleParameters.addSource(image);
        rescaleParameters.add(xScaleFactor);
        rescaleParameters.add(yScaleFactor);
        // saving as TIFF is a little more complicated than loading
        try
            FileOutputStream out = new FileOutputStream(outputFilename);
            TIFFEncodeParam parameters = new TIFFEncodeParam();
            ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", out, parameters);
            try
                encoder.encode(image);
                out.close();
            catch (IOException e)
                System.out.println("Failed to encode the image");
        catch (java.io.FileNotFoundException ioEx)
            System.out.println("Could not write to file " + filename);

Similar Messages

  • Change image resolution using image events

    Does anyone have an applescript to change image resolution using image events in OSX? I want to optimize my images for iWeb. I want to use a shell script in an applescript as a droplet or as a service in Automator. I'd like to leave the original intact.

    No? Oh...ok den. No Applescripts at all.

  • Applescript to change image resolution using image events

    Does anyone have an applescript to change image resolution using image events in OSX? I want to optimize my images for iWeb. I want to use a shell script in an applescript as a droplet or as a service in Automator. I'd like to leave the original intact.

    For what type of use in iWeb are these photos intended? If it's for adding to a page (not a photo or album page) iWeb does a great job of optimizing. See my post in this topic: Re: Photo Resolution in iWeb.
    You can optimize an entire site with an application like Web Site Maestro. It can reduce the site's size by up to 49%. Here's the settings available for the optimization:
    Click to view full size
    It's very effective.
    OT

  • Wrong image resolution for TIF file

    Under OSX 10.6.2, the image resolution using Preview application is wrong for FAX MultiPages TIFF files.
    If I open up a file with this resolution:
    Image size: 1728 x 1081 pixels
    Image DPI: 204 x 98 pixels/inch
    Color Model: Gray.
    The image always show up all squeezed vertically which tells me the Preview application is not processing the DPI properly. When using the size menu from tools, it assumes the resolution is the same for vertical and horizontal which is wrong.
    I'm unable to use the Preview application to read FAX TIFF files with the standard FAX resolution.
    How do I open up a trouble ticket with Apple developers to fix this issue? I believe it's a software design issue assuming that all TIFF files use the same resolution for both horizontal and vertical DPI. The Preview application should be able to handle different DPI for horizontal and vertical resolution.
    We're a small business and we are running the whole office with Mac Minis and iMac with a Mac Mini Server of course. We love it, but we have this annoying bug which I don't have any way to fix it.
    Thank you,
    Stephan Monette
    Unlimitel Inc.

    Here's a sample of the tif file from our fax machine you can download:
    http://www.hmnet.net/warp2/fax-standard.tif
    Download the file on your desktop and try opening it. You will see the square at the bottom will look like a rectangle. With the right resolution, it should look like a square, not a rectangle.
    If I open the file with Windows picture and fax viewer, the resolution is fine and the square looks like a square. But the same file on Windows with Quicktime fails to open and it complains about a corrupted file.
    On my MAC, the file opens with Preview, but the resolution is wrong.
    Maybe the FAX server is not formatting the TIFF file properly, but we can't fix that since there's no more support for it. But the Windows app is able to open it up with the right resolution. So maybe it's just some code change to do in the Preview app.
    Thanks,
    Stephan Monette
    Unlimitel Inc.

  • JPEG image resolution conversion

    HI,
    Is is possible to change jpeg image resolution using awt or some other way ?
    Thanx

    Im not sure about using awt if you can do it but look up the API's java.awt.*
    There are programs out there that change JPEG resolution though.

  • Why Does Photo Image Resolution Get Downgraded In CS3?

    Hi,
    I admit from the outset that I am a Photoshop dunce, and try to run before I can walk. That said, I can get simple things done but cannot figuire out why this is happening or what to do.
    I am creating a CD box image in CS3 using a pre-created Action to make the box image that was obtained elsewhere. The problem is that when I bring in a very high quality photo (231KB), it downgrades in resolution. When it first comes in, it is gigantic and of high quality. However, when I resize it, it becomes of poor quality. I think I apply the transform when this happens?
    Any advice would be appreciated. Thank you.
    Asoka

    Thank you very much for your feedback and help.
    Actually, you're right about the image. I myself had a big question mark about the "high resolution image" when I went off to find the file size for this forum post, only to discover that it was less than even 1MB. Not exactly the highest resolution after all!
    I got it from iStockphoto, and it was the small version of the images that I chose, i.e. for web use primarily. But I found that I was able to do a product box, even a website banner, without any problem at all. Also, when I bring it into Photoshop, it seems to be a mile wide on a 32 inch monitor but still shows pretty high definition. That is why I thought it was high resolution.
    What I can't understand is that I created a product box with another Action with the same images and that came out just fine. It's when I try this CD box that the image quality seems to mysteriously downgrade.
    You can see the product box here:
    http://www.surgeyourtradingsuccess.com/surgebm/
    and as you see, the result is actually quite good (and these are the same images photos, i.e. under 1MB file size).
    However, when I do the CD case, this is what I get:
    http://www.surgeyourtradingsuccess.com/Case.htm
    You are correct that one should not really be working with Actions until one is experienced in the basic product. In my defense, I didn't create the Actions but rather bought them as part of a graphics product: in other words, they were pre-created so that all I have to do is add the appropriate photos, backgrounds and text and then hit the buttons. It worked fine for the product box graphic and also for this CD box graphic, EXCEPT that the latter result is low resolution.
    Any thoughts on what is happening?
    Asoka

  • Problem Printing Images Using JAI

    I'm using JAI in an application that prints images. My program works fine on my development machine (Windows XP), but when I put it on my Windows Server 2008 r2-64 bit, it crashes for certain images (these are large images of land plats) that go to a particular printer (OCE PlotWave 300) It prints my smaller images that are printing on a variety of printers just fine (images of Mortgages etc..) and it prints everything just fine on my development machine. What could possibly be causing this?
    Edited by: LongStranjeTrip on Feb 2, 2011 4:34 PM
    Edited by: LongStranjeTrip on Feb 4, 2011 8:11 AM

    I'm using JAI in an application that prints images. My program works fine on my development machine (Windows XP), but when I put it on my Windows Server 2008 r2-64 bit, it crashes for certain images (these are large images of land plats) that go to a particular printer (OCE PlotWave 300) It prints my smaller images that are printing on a variety of printers just fine (images of Mortgages etc..) and it prints everything just fine on my development machine. What could possibly be causing this?
    Edited by: LongStranjeTrip on Feb 2, 2011 4:34 PM
    Edited by: LongStranjeTrip on Feb 4, 2011 8:11 AM

  • How to resize image in JSP using JAI ??!!

    Please help me how to resize an JPEG image from my JSP, could I use JAI lib ? how ?

    Hello,
    I had the same problem few months ago ( in that case i used Jimi instead of JAI).
    The answer to your question is: use the java class called "Image".
    Infact you can use JAI just for load or save to disk your image that you have to resize and then use the following code to resize the image :
    Image imgResized = img.getScaledInstance(100,1,Image.SCALE_AREA_AVERAGING);
    The object "img" is the image to resize and the object "imgResized" is the image resized with width equals to 100 and with a right height.
    I used Jimi just to save my image and i think that with JAI there is a method to do this.
    You can use JAI to load in memory your image too so you can avoid problem with MediaTraker class.
    I hope that this can help you.
    Cheers.
    Stefano

  • Setting Image resolution of the images created by Powerpoint conversion service using PictureRequest class

    I am using PictureRequest class to get the images of the presentation as,
    PictureRequest request = new PictureRequest(inStream, ".pptx", PictureFormat.Png, outStream);
    IAsyncResult result = request.BeginConvert(SPServiceContext.GetContext(siteCollection), null, null);
    request.EndConvert(result);
    After getting the response from the PictureRequest if I check the image size (in this case png) it has the resolution of 720x540. I want bigger resolution images. I searched all over the sharepoint central administration but could not find any setting related
    to Powerpoint conversion service which may allow to set the desired image resolution.
    Could you please anyone suggest where I can specify the required resolution?
    Many thanks in advance!

    Hi,
    According to your description, you want to convert PPT file to PNG file in a specific resolution.
    There is no such OOTB settings in PowerPoint conversion service can meet your requirement. In
    PictureRequest object, there is also no related method can set the resolution of the converting image.
    As a workaround, I would suggest you do the conversion outside SharePoint, there will be more options available to handle the properties of the converted images.
    The links below about with code demos about how to convert PowerPoint Slide to Image for your reference:
    http://www.free-power-point-templates.com/articles/c-code-to-convert-powerpoint-to-image/
    http://www.codeproject.com/Articles/10632/Export-of-PowerPoint-slides-to-high-quality-Bitmap
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to improve image resolution with using filters

    how to improve image resolution with using filters?

    image resolution, Please check the below links. They should give you a clear idea about Resizing and resampling images.
    http://helpx.adobe.com/photoshop/kb/advanced-cropping-resizing-resampling-photoshop.html#m ain_Resizing_and_resampling_images
    Understanding Resize vs. Resample | Learn Photoshop CS6 | Adobe TV
    Cheers!
    ~ Arpit

  • What image resolution should use for the new iPad with Retina display?

    What image resolution should use for the new iPad with Retina display?

    http://www.ipadcasereview.com/ipad-3-cases-and-covers-top-of-page/#sthash.hZKnxH ku.dpbs
    these are the best

  • Original Image Resolution and Color getting Distorted

    Hi All,
    I am using JAI for reading images from a source i have to read the images and than have to split the images
    initially i was using ImageIO.read() method to read images but for some images it was throwing error as
    javax.imageio.IIOException: Unsupported Image Type
         at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
         at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source)
         at javax.imageio.ImageIO.read(Unknown Source)
         at javax.imageio.ImageIO.read(Unknown Source)
         at deepzoomconvertor.Main.loadImage(Main.java:370)
         at deepzoomconvertor.Main.processImageFile(Main.java:238)
         at deepzoomconvertor.Main.reteriveAllImages(Main.java:221)
         at deepzoomconvertor.Main.main(Main.java:86)so in such exception cases i am trying to read the images using JAI and i am successful in reading images
    here is the piece of code i am using for this
      BufferedImage result = null;
       SeekableStream ss=SeekableStream.wrapInputStream(new FileInputStream(file), false);
               ParameterBlock pb = new ParameterBlock();
               pb.add(ss);
               RenderedOp rm=JAI.create("JPEG", pb);
               result=rm.getAsBufferedImage();
                 return result;it able to split images but the quality of images are poor it losts its original color format.
    can any one have any idea how to do it while retaining the quality of image color and resolution
    Thanks in advance
    Umesh

    The JPEG you are reading is a cmyk color space one. They're not common, but they do occasionally pop up in a collection of random jpeg images.
    The default JPEGImageReader that comes with the jdk cannot read them. And it will throw an exception - the exact same one you got - stating it can't. JAI's behavior is a little worse. It will read the image without exception, when in fact it to can't read it. It doesn't handle the cmyk aspect right, so you get a messed up image.
    The native JPEGImageReader that comes with installing [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html] can read them. It appropriately decodes the ICC_Profile embedded within the JPEG and you get a cmyk BufferedImage. But if you wish to render this TYPE_CUSTOM BufferedImage, go grab a coffee while you wait for it to slooooowwwllly paint. You'll have to do a ColorConverOp to turn the cmyk BufferedImage into an rgb one (so Java2D can render it fast).
    Having done all this you'll find that 1) ColorConvertOp makes the image too bright and 2) The native PNGImageReader that comes with installing JAI-ImageIO has an affinity for returning TYPE_CUSTOM BufferedImages (arggg!!!).
    I'll help you fix points (1) and (2) if you get that far. Maybe the best choice is to simply give up on cmyk jpegs. They're only used in printing press environments, and people only use color space aware applications (like Photoshop) to manipulate them in any meaningful way.

  • IPhoto is Downgrading Photo Resolution

    I attempted to follow a link to a branched discussion but was not "authorized" to do so.
    iPhoto has significantly downgraded the resolution of photos I'm storing in it.  I have thousands of 12mp images that now are no larger than 1280x960 (and no, not the thumbnails, the opened pics with the info pane open next to them).
    I read in earlier posts something about the originals being stored somewhere else on my hard drive, but have not been able to locate them.
    Does anyone have any idea where I might find them or if there is another reason this is happening?
    All help is appreciated!

    If rebuilding with iPhoto doesn't seem to fix the problem try the following:
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    1 - download iPhoto Library Manager and launch.>Click on the Add Library button,
    2 -  select the library you want to add from those in the selection window.
    3 - make sure that in the rebuild window the checkbox  "Scavange orphaned photos" is checked.
    4 - now that the library is listed in the left hand pane of iPLM, click on your library and go to the Library ➙ Rebuild Library menu option
    5 - in the next  window name the new library and select the location you want it to be placed. Click on the Create button.
    Note 1: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments. However, books, calendars, cards and slideshows will be lost.
    Note 2:  Your current library will be left untouched for further attempts at a fix if so desired.
    If the original files in this library show the full pixel dimensions and so so for some time then you can continue using this rebuilt library and trash your current library. 

  • Overprint Preview, RGB, Image Resolution Acrobat v9

    I recently started using Acrobat 9. There is 2 things I'm looking in V9.
    1- Overprint Preview
    2- All image resolutions in a HiRes pdf. I see a custom check profile called "resolution of color & grayscale images is between..." but I want image resolution is ...
    3- Flag any RGB images used.
    ThankYou

    I'm sorry what I mean if a pdf have 35 images I would to see the image resolution of all of them independently if they are 72 or 600 dpi.

  • Continuous tone image resolution lower than specified

    The following message was posted in the incorrect forum; no legitimate solution to the problem was ever posted. I am re-posting it, as this is the same exact problem I am having, right down to the OS and version of Acrobat. Could someone please explain to me what this means and whether or not I should be concerned about it? I will also get two different kinds of results... one is a single number effective ppi on this error, such as 199, (which results in 200ppi if run through PitStop), and a two-number effective ppi, which we haven't been able to decipher, such as 501.357/179.55ppi (which should be a hi-resolution image).
    Help?
    Amy Carolyn Watson
    >
    >
    >Nikola Viereckel - 09:45pm Dec 9, 2007 Pacific
    >
    >Hi - I have recently discovered the above error message when I
    >check my distilled press quality pdf in preflight. I am using
    >a PC and Version 7.0 of distiller and acrobat. The images are
    >300dpi and are in my documents at 100% or lower, so there should
    >be no resolution issues. The pdf itself looks fine, but the
    >preflight does not. I find if I export out of InDesign (CS2)
    >then I do not get the same error message, but this is not my
    >preferred way to create pdfs for print.
    >
    >Any ideas? I the only thoughts I have had is to reinstall
    >the program. Thanking you in advance for your help.
    >Cheers
    >Nikola

    > All text should export as vector, since it's all on a layer above any kind of image.
    Is there any transparency in the text, though? If you float text over
    an image with transparency, it MUST be exported as an image. If it is
    floated over vector art with transparency, it MIGHT.
    It's easy to assume that just because something is on top, it doesn't
    ever need to be flattened. This is not in fact true.
    >
    >I am a little concerned: is this a flaw in the Acrobat Program?
    You mean in its preflight? Unlikely, it isn't rocket science to
    calculate ppi, so the numbers are probably right.
    >
    >Where is this "Continuous tone image resolution" turned on/off? Why is it important?
    That's probably a reference to Distiller settings. I think we've
    established that you aren't using Distiller.
    >
    >Is InDesignCS2 flattening to low transparency settings, even though my settings dictate high?
    You'd probably need to ask in the InDesign forum. But bear in mind
    that the flattener is free to use lower resolution if it thinks that
    is all that is needed for particular effects.
    Maybe you could reopen the PDF in Illustrator, and use that to select
    the images in the flattened page. Might illuminate what is going on.
    Aandi Inston

Maybe you are looking for