Reading TIFF, Writing JPEG with Advanced Imaging

I am working on a servlet that will read a TIFF image file from a SOCKET connection, and write it to a JPEG file for viewing by the user. I've been able to read the TIFF file into a byte array, but I'm not sure how to write it back out as a JPEG. The code snippet below is being used to read the TIFF from the SOCKET:
for (int i=0; i < imageCount; i++)
imageSocket = new Socket("imageServer", 4178);
toImage = new PrintWriter(imageSocket.getOutputStream(), true);
fromImage = new BufferedReader(new InputStreamReader(imageSocket.getInputStream()));
toImage.println(imageNames);
int fileSize = Integer.parseInt(fromImage.readLine());
if (fileSize > 0)
byte[] image = new byte[fileSize];
for (int j=0; j < fileSize; j++)
image[j] = (byte) fromImage.read();                
else
System.out.println("file size is zero"); /* display msg for now */
I'd prefer to do this using the Advanced Imaging API,s but can't find a decent example to look at. Can anyone help me find a better way of doing this?
Thanks!

You will get some help from following guide.
http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/index.html

Similar Messages

  • Losing metadata after TIFF to JPEG conversion in Image Processor

    When I use Image Processor to convert TIFF to JPEG for my images I am losing metadata information placed in the Properties section of my image file (PC). Is there a work-around for this so that the information isn't lost? Any idea why this is happening?

      Possibly the tiff is 16 bit.
    In Full Edit click Image à Mode à 8 Bit/channel
    Then save as jpeg.
     

  • 2215 EIT failure. VA recoad read failure.ensure drive with VA image is not installed correctly

    2215 EIT failure. VA recoad read failure.ensure drive with VA image is not installed correctly

    Hello 8022,
    I understand you are getting the "2215-EIT failure. VA boot record read failure. ensure drive with VA image is installed correctly" error. I would be happy to assist you, but first I would encourage you to post your product number for your computer. I am linking an HP Support document below that will show you how to find your product number. As with this we can provide you with accurate information.
    How Do I Find My Model Number or Product Number?
    Please re-post with the requested information and I would be happy to provide you with assistance. Thank you for posting on the HP Forums. Have a great day!
    Please click the "Thumbs Up" on the bottom right of this post to say thank you if you appreciate the support I provide!
    Also be sure to mark my post as “Accept as Solution" if you feel my post solved your issue, it will help others who face the same challenge find the same solution.
    Dunidar
    I work on behalf of HP
    Find out a bit more about me by checking out my profile!
    "Customers don’t expect you to be perfect. They do expect you to fix things when they go wrong." ~ Donald Porter

  • Writing JPEG with ImageIO

    Hi,
    I wanted to do this little tool that:
    1. read any type of image format supported by ImageIO
    2. scaled it down to arbitrary size
    3. wrote the image to the same format it was originally
    I got the pieces together, used ImageIO to read the image, then java.awt.image.AffineTransformOp to scale it down and finally ImageIO again to write it back (I get the ImageWriter with ImageIO.getImageWriter(ImageReader)).
    The problem I got was that AffineTransformOp on Linux (it uses native code) does not want to output anything else then ARGB images. If I read a YCbCr JPEG (the most common JPEG format) and do the AffineTransformOp, I get this ARGB image, which ImageIO will happily write back as an JPEG, but as CMYK JPEG file (which is really rare and not understood by most browsers)... which is not fine because the original was YCbCr.
    The question now is, how do I get AffineTransformOp and ImageIO to play nicely together. Either I have to get AffineTransformOp to output to an BufferedImage that has the same colormodel as that read from the file, or I have to get ImageIO to write any BufferedImage to the exact same format as the original image file.
    For the special case I stated above, I got the program to work by converting the BufferedImage I got from AffineTransformOp to a BufferedImage with RGB colormodel. This, however is not the solution because it assumes that we do not want to output ARGB... Anyway I did it whith the following code (yes, it is horrible).
    // do scaling
    BufferedImage scaled = op.filter(original, null);
    // create a new RGB color model... no alpha
    ColorModel rgbcm = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
    // get the DataBuffer from the scaled version
    DataBuffer db = scaled.getRaster().getDataBuffer();
    // and its dimensions
    int w = scaled.getRaster().getWidth();
    int h = scaled.getRaster().getHeight();
    // band masks for rgb (no alpha)
    int[] bandMasks = new int[] {0x00ff0000,0x0000ff00, 0x000000ff}
    // create new WritableRaster that has the same data, but different sample model
    WritableRaster r = Raster.createPackedRaster(db, w, h, h, bandMasks, null);
    // create a new BufferedImage with the no-alpha ColorModel and the raster
    // with no-alpha SampleModel
    BufferedImage rgbimg = new BufferedImage(rgbcm,r, scaled.isAlphaPremultiplied(), null);
    My second question is, if I have to do this, is there any simpler way?

    I just did a project similar to this actually, so you're in luck! My project was doing image compression rather than resizing, but the IO is the same. I used PixelGrabber to get the pixels, then created my new image in a BufferedImage just like you did (so you can keep all your reading and image creation the same since you seemed to use a BufferedImage also).
    Once you have your BufferedImage, it's blazingly simple. There is a JPEGCodec package that is included in the JDK. It's not compiled though. but, if you open up the ZIP file that has the sources in it (it's copied to your java home directory, called "src.zip"), you can get all the sources you needed. In that package there are 2 classes that I used: JPEGCodec and JPEGImageEncoder. It works like follows:BufferedImage bi;
    OutputStream os;
    // create and fill your buffered image and instantiate your output stream (I used a FileOutputStream for obvious reasons).
    JPEGImageEncoder jie = JPEGCodec.createJPEGEncoder(os);
    jie.encode(bi); And that's it! The package does the rest! Let me know if you have any troubles with it.

  • Converting TIFF to JPEG with sips, then import into iPhoto problems

    I am cataloguing a box of slides and negatives for my family. The scanner generates huge TIFF files (on purpose), and I have an Applescript that then uses sips to copy them into low quality JPEG files using this command:
    do shell script ("sips -s format jpeg -s formatOptions low -s description " & "'" & "Original path: " & (POSIX path of an_image) & "'" & space & (POSIX path of an_image) & " --out " & new_file)
    where an_image is the source file, and new_file is the path and name of the converted image.
    This way, I can save the original file path as the image's description while shrinking the file size to speed up later importing into iPhoto. As part of the iPhoto import, that description from the metadata is placed in the on screen comment section for each image.
    This works fine to do the initial shrinking, but less than half of the resulting jpeg files can subsequently be imported into iPhoto. I get this error:
    The following file could not be imported. (The file is in an unrecognizable format.)
    And yet, Preview and Safari both open the files with no problems.
    Is there anything else I need to set when doing the conversion with sips to make it easier for iPhoto to recognize the converted files?
    I have over 1000 images, and anticipate a final total of about 2500 when I am done. These are images of myself and my siblings from the 1960s and 1970s, and my idea is to scan them all at high resolution, and use the converted, smaller files for iPhoto for keywording and Faces to get them organized, while retaining the paths to the original images. Any commentary is appreciated.

    I have uploaded one of the bad JPG files here:
    www.mrcodeboy.com/smith/Try.jpg
    I tried examining the metadata with exiftool, Image Events, and mdls, but there are a number of differences between the TIFF metadata and the JPEG metadata structures. I found no obvious differences, but this is a good idea, and I will continue to examine those closely for clues.
    *EDIT*
    I downloaded the bad JPEG above onto a different machine; it still does not import into iPhoto. However, by invoking sips on that file to convert it back to a TIFF file thusly:
    sips -s format tiff Try.jpg --out TryTF.tif
    it imported just fine. There has to be some sort of parameter that is NOT being addressed in the conversion from TIFF to JPEG that is somehow messing this up, yet is preserved when the file is re-written as a TIFF.
    Message was edited by: casdvm

  • Exporting to jpeg with grayscale images on the page crashes Indesign

    Hi,
    I have noticed a bug in Indesign CS4.
    When I have grayscale psd images on a page the export to jpeg crashes.
    - R

    That's been happening to me too, but I didn't realize it was just the grayscale .psd causing it, since I never use the feature in the real world and was only trying to confirm a posted behavior.
    Report it here: http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • In photoshop cc my saved files don't appear as thumbnails with the image, only with the generic tiff or jpeg icon

    how do i get actual thumbnail images in photoshop cc instead of generic tiff or jpeg icons??

    And what exactly? If you mean system thumbnails, then this has nothing to do with PS. You messed up your file associations then by installing a tool that usurped those associations and they no longer default to the Windows preview function.
    Mylenium

  • How to set color space to JPEG image with Java advance Imaging

    How to set color space to JPEG image with Java advance Imaging.
    is there any API in JAI which support to set color space.

    I'm definately no guru, but this is how you can change it.
    CTRL + ALT + Click on the part of the component that you want to change. This brings up the Hidden Dom Inspector, background of component will be surrounded with a red outline (Make sure the red outline is surrounding the part of the tabset you want to change), Now you go to properties sheet and click the ellipses next to rules property this will pop up a dialog you look in this list (At the top) to see the default style classes that are affecting the rendering of the component outlined in red. (You will be able to select different sections of a single component) then you just rewrite the style class that you want to change in your Stylesheet (You will not find the styleclass that you want to change because it is a part of your theme .jar but as long as you name it exactly the same and place in your stylesheet it will override the theme .jar style classes) it's actually very easy -- you were right should be a piece of cake for a guru. Don't have the link handy but you can check out Winston's Blog on changing Table Formatting to get this information...It is EXTREMELY useful if you want your apps to have a custom look and not default that comes with Creator Themes.
    Hope this helps you out God knows others have helped me alot!
    Jason

  • ImageIo: reading and writing a jpeg corrupts the image

    Sometimes, ImageIo manages to read an image wrong. If I simply read() and write() the
    image without any transformations, the image writtten will have its colors all wrong. The
    output image format here doesn't matter.
    An example image is: http://bram.name/~brama/pics/test.jpg
    And output after reading and writing it: http://bram.name/~brama/pics/test_output.jpg
    Is the image io lib to blame, or is it a broken image? The image displays fine in other programs.
    Message was edited by:
    Bram_A

    Use this code to load the image.
    From my experience it is much more stable and also faster.
    My guess is that the problem is related to the ICC profile embeded in the JPEG.
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new URL("http://www.stack.nl/~brama/pics/imageio.jpg").openStream());
    BufferedImage image = decoder.decodeAsBufferedImage();

  • How to read and write Png and jpeg with  Alpha

    Hi
    I have trouble reading and writeing PNG and JPEGs that have an alpha channel (for transparency).
    Reading works, if i use Toolkit.getImage() method, but works NOT if i use ImageIO.read() method.
    Writing does NOT work using ImageIO.write()method. Instead i got a "java.lang.UnsupportedOperationException: Unsupported write variant!"
    See Test class and commandline output below:
    /****************START*****************************/
    package de.multivisual.bodo.test;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.File;
    import java.net.URL;
    import java.util.Iterator;
    import javax.imageio.*;
    import javax.imageio.metadata.IIOMetadata;
    import javax.imageio.stream.ImageInputStream;
    import javax.imageio.stream.ImageOutputStream;
    public class AlphaChannelTest implements ImageObserver {
      Toolkit toolkit;
      Image img;
      public AlphaChannelTest() {
        super();
        toolkit = Toolkit.getDefaultToolkit();
        URL url =
          AlphaChannelTest.class.getResource(
            "/de/multivisual/bodo/test/" + "alphatest.png");
        img = toolkit.getImage(url);
        try {
          ImageInputStream imageInput =
            ImageIO.createImageInputStream(url.openStream());
          Iterator it = ImageIO.getImageReaders(imageInput);
          ImageReader reader = null;
          while (it.hasNext()) {
            reader = (ImageReader) it.next();
            System.out.println(reader.toString());
          reader.setInput(imageInput);
          ImageReadParam param = reader.getDefaultReadParam();
          BufferedImage bimg = reader.read(0, param);
          SampleModel samMod = bimg.getSampleModel();
          ColorModel colMod =       bimg.getColorModel();
          String[] propNames = bimg.getPropertyNames();
          IIOMetadata meta = reader.getImageMetadata(0);
          System.err.println("\n*****test image that was read using new Jdk 1.4 ImageIO.read() method");
          alphaTest(bimg);
        } catch (Exception e) {
          //e.printStackTrace();
        if (img != null)
          toolkit.prepareImage(img, -1, -1, this);
        try {
          synchronized (this) {
            System.out.println("wait");
            this.wait();
        } catch (Exception e) {
          e.printStackTrace();
        System.out.println("end");
      public void alphaTest(BufferedImage bi) {
        Raster raster = bi.getData();
        float[] sample = null;
        System.out.println("raster :");
        for (int y = 0; y < raster.getHeight(); y++) {
          for (int x = 0; x < raster.getWidth(); x++) {
            sample = raster.getPixel(x, y, sample);
            System.out.print("(");
            for (int i = 0; i < sample.length; i++) {
              System.out.print(":" + sample);
    System.out.print(")");
    System.out.println();
    Raster araster = bi.getAlphaRaster();
    if (araster == null){
         System.err.println("there is no Alpha channel!!!!!!!!!");
         return ;
    } else {
         System.out.println("Alpha channel found !");
    float[] asample = null;
    System.out.println("raster alpha:");
    for (int y = 0; y < araster.getHeight(); y++) {
    for (int x = 0; x < araster.getWidth(); x++) {
    asample = araster.getPixel(x, y, asample);
    for (int i = 0; i < asample.length; i++) {
    System.out.print(" " + asample[i]);
    System.out.println();
    String format ="PNG";
    System.out.println("##########Test Writing using new JDK1.4.1 ImageIO:");
    Iterator writers = ImageIO.getImageWritersByFormatName(format);
    ImageWriter writer = (ImageWriter) writers.next();
    ImageWriteParam param = writer.getDefaultWriteParam();
    ImageTypeSpecifier imTy = param.getDestinationType();
    ImageTypeSpecifier imTySp =
    ImageTypeSpecifier.createFromRenderedImage(bi);
    param.setDestinationType(imTySp);
    File f = new File("c:/tmp/myimage."+format);
    try {
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    writer.setOutput(ios);
    writer.writeInsert(0, new IIOImage(bi, null, null), param);
    } catch (Exception e) {
         System.err.println("could not write "+format+" file with alpha channel !");
    e.printStackTrace();
    public boolean imageUpdate(
    Image img,
    int infoflags,
    int x,
    int y,
    int width,
    int height) {
    if ((toolkit.checkImage(img, -1, -1, null)
    & (ImageObserver.HEIGHT | ImageObserver.WIDTH | ImageObserver.ALLBITS))
    == 35) {
    int iw = img.getWidth(this);
    int ih = img.getHeight(this);
    BufferedImage bi = new BufferedImage(iw, ih, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D big = bi.createGraphics();
    big.drawImage(img, 0, 0, this);
    System.err.println("+++++test image that was read using old Toolkti.getImage method");
    alphaTest(bi);
    synchronized (this) {
    this.notifyAll();
    return false;
    return true; // image is not yet completely loaded into memory
    public static void main(String[] args) {
    //     BufferedImage image = new
    // BufferedImage();
    new AlphaChannelTest();
    /*************************END********************/
    The commandline looks like this:
    [i]
    com.sun.imageio.plugins.png.PNGImageReader@d1fa5
    *****test image that was read using new Jdk 1.4 ImageIO.read() method
    raster :
    there is no Alpha channel!!!!!!!!!
    wait
    +++++test image that was read using old Toolkti.getImage method
    raster :
    Alpha channel found !
    raster alpha:
    ##########Test Writing using new JDK1.4.1 ImageIO:
    could not write PNG file with alpha channel !
    java.lang.UnsupportedOperationException: Unsupported write variant!
         at javax.imageio.ImageWriter.unsupported(ImageWriter.java:600)
         at javax.imageio.ImageWriter.writeInsert(ImageWriter.java:973)
         at de.multivisual.bodo.test.AlphaChannelTest.alphaTest(AlphaChannelTest.java:113)
         at de.multivisual.bodo.test.AlphaChannelTest.imageUpdate(AlphaChannelTest.java:135)
         at sun.awt.image.ImageWatched.newInfo(ImageWatched.java:55)
         at sun.awt.image.ImageRepresentation.imageComplete(ImageRepresentation.java:636)
         at sun.awt.image.ImageDecoder.imageComplete(ImageDecoder.java:135)
         at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:511)
         at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:257)
         at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:168)
         at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    end

    in between i found out that the my png and jpeg test images did not have an alpha channel, since the tool i used to create them, did not write the alpha channel to disk.
    if i use png with alpha channel, then the read works correktly with ImageIO.read()
    however the read problem still remains for gifs and the write does not work for gifs and neither for pngs.
    whether jpegs can be read with alphachannel i don't know since i don't have a tool to create jpeg with alpha channel. (at least gimp and corel9 are not able to )
    and it is not possible to write the previous read png with alpha channel back as and jpeg with alpha channel

  • Calendar images: RGB or CMYK? TIFF or JPEG?

    Why am I not finding this info anywhere? Prior to making a calendar and/or book, I'm going to edit my images in Photoshop, then save them out, but want to know in advance the ideal size (300 dpi at final size? At what line screen are the books/calendars printed?). Am I saving in CMYK as you would for regular 4 colour printing? Or do they need to be RGB? What format? TIFF files, again, as you would for normal 4-colour sheetfed offset printing, or JPEGs? Answers to these questions as a link on one of the myriad help pages would be nice.
    Thanks.

    Why am I not finding this info anywhere? Prior to making a calendar and/or book, I'm going to edit my images in Photoshop, then save them out, but want to know in advance the ideal size (300 dpi at final size?
    dpi has no mening for a digital photo - See The Myth of DPI for additional information. - you want to save at the full pixel size that you have for maximum quality
    At what line screen are the books/calendars printed?).
    It is not a printing press but a digital printer - the higher quality you have the better the print - any print that will print below 180 dpi gives you a warning
    Am I saving in CMYK as you would for regular 4 colour printing?
    No - iPhoto ONLY works with RBG images
    Or do they need to be RGB?
    Yes
    What format? TIFF files, again, as you would for normal 4-colour sheetfed offset printing, or JPEGs?
    Your choice - most people use JPEG to reduce disk storage - TIFF is fine too
    LN

  • Working with tiff and jpeg?

    1. ACR saves changes made to a raw image into the sidecar file, though what is it doing with the tiff or jpeg file that is changed? Where is this saved?
    2.what features do you not have if you open tiff or jpeg in ACR?  It seems to do everything the same.
    Thanks.

    The settings are saved as xmp metadata inside the jpeg/tiff. Note that while the settings are saved (and show up in Bridge), the settings are not actually applied until you actually process the images. So other 3rd party viewers won't see the changes. The embedded metadata is done safely and will not impact the file. The xmp metadata is also stored inside of DNG files as well. Only proprietary raw files force the use of sidecar files because ACR/Adobe treats them as read only files (it's not "safe" to write metadata in proprietary raw files since the formats are not documented).
    As to limitations, since jpeg/tiff files are already rendered into a color space and gamma, those files are not "linear" and you will be limited in the amount of highlight recovery that can be done. Additionally, since the rendered files already have a white point the white balance is somewhat limited as well. Also, there are limitations to the Lens Corrections because ACR can't apply lens correction built for raw files in jpeg/tiff files. You can still use the manual corrections...

  • Reading TIFF images without IMAQ vision

    Hi,
    Is there anyway to read TIFF images with LV 7.1 but without IMAQ vision? I know it's possible for PNG, BMP and JPEGs, but seems impossible to read TIFFs without IMAQ Vision.
    Thanks.
    Kian

    LabVIEW doesn't do this automatically, but maybe someone has a VI they're willing to share.
    Another possibility would be to use an external program to convert the TIFF to another format (BMP for example) and then to read in the BMP picture.
    If you're looking to write something yourself, then this might help.
    Hope this helps
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • "Save image" button of Camera Raw does not save JPEG with modifications made.

    I am using Bridge CC to process my RAW images and make modifications to some JPEG images as well.  I have no need to further alter images in Photoshop at the moment, so I do all modifications in Camera Raw. After altering my images, I then press the "save image" button at the left bottom corner of Camera Raw and choose the settings to save in JPEG.  However, when I upload these JPEG images to a website or when I email them, the image is uploaded without the modifications I had done!  It seems to me that Camera Raw is saving JPEGs the same way it does for RAW images, in a non-destructive manner, only attaching instructions for the images to be displayed properly on Photoshop. But when I save an image in JPEG, I expect the image to be saved entirely with the modifications I made while still keeping the original RAW file.  What goes on then?  What is Camera Raw doing and how do I get to save a modified image in JPEG with Camera Raw?  Would you please explain?
    Many thanks for your help,
    Beza

    Hi,
    What version of camera raw and operating system are you using?

  • 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

Maybe you are looking for

  • Black Bars in Program Monitor - Why?

    Todd Kopriva, from Adobe, has just done a nice TUTORIAL, addressing "black bars," around the image in the Program Monitor. Todd uses PrPro CS 5.5 for his demo, but nearly everything, save a few mechanical differences, will apply to other versions of

  • Can I use Word tables in InDesign?  Any way to import tables made with Word?

    Hi, I'm new here...  Well, the title says it all: I need to use (basically unchanged) nearly 100 tables from a book made recently with Word... Can I import them? It wouldn't be a problem making one new one (lines, etc...) with InDesign and then fill

  • Calling UDF (MS Access) from Excel VBA

    Hi, I need to run a query on an MS Access database that has to perform a weekday calculation between two date columns, and this query has two date parameters that it receives dynamically. I am using Excel VBA as the front end. Select AgeRange, count(

  • InDesign Table question

    i have been working in InDesign CS3 for several years, upgraded to CS6 today. Am attempting to edit a table in my document. Am not being allowed to even select this table. What can i do? Thanks rlholdren

  • Unable to play youtube videos - using proxy (squid)

    Youtube videos do not play in my configuration. Most youtube content appears, but attempting to play a video results in a popup message "This movie could not be played". Sorry for the length of the post, but I'm trying to get enough documentation dow