Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8057666

Error in JPG Colorspace detection while reading using ImageIO

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u20
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

      Also seen with

      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux localhost.localdomain 3.15.7-200.fc20.x86_64 #1 SMP Mon Jul 28 18:50:26 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

      Also seen on ubuntu 14.04

      A DESCRIPTION OF THE PROBLEM :
      When trying to read a JPG and just write it back to another file, the colors of the image are all screwed up. From browsing on the internet, Its basically whats mentioned here

      http://stackoverflow.com/questions/13072312/jpeg-image-color-gets-drastically-changed-after-just-imageio-read-and-imageio

      The sample Image I tried with is here - http://img1.junaroad.com/uiproducts/34199/pri-1384240030.jpg

      I am uploading the same original image as well as the wrong saved image on imgur in case the original link goes missing. Here is the imgur album - http://imgur.com/a/barYY

      There is a chance imgur is resampling the image, so use the original URL i gave. If thats not working you can ping me on my email and i can provide newer source image

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
                  BufferedImage originalImage;
                  try {
                      originalImage = ImageIO.read(inputFileInputStream); // simple FileInputStream to the image file
                      
                      
                      if (originalImage == null) {
                          throw new Exception("error");
                      }
                     
                      try {
                          

                  FileOutputStream output = new FileOutputStream("/outputPath/outputimage");
                  ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpeg").next();
                  ImageWriteParam iwp = jpgWriter.getDefaultWriteParam();
                  iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                  iwp.setCompressionQuality(0.95f);
                  ImageOutputStream imageOutput = ImageIO.createImageOutputStream(output);
                  jpgWriter.setOutput(imageOutput);
                  jpgWriter.write(null, new IIOImage(originalimage, null, null), iwp);
                  jpgWriter.dispose();
                  imageOutput.flush();



                      } catch (Exception ex) {
                          ex.printStackTrace();
                      }
                      
                      
                      
                  } catch (FileNotFoundException ex) {
                      throw new ImageNotFoundException(ex.getMessage());
                  }

      ACTUAL -
      http://imgur.com/a/barYY

      The image with red background is the wrong result

      REPRODUCIBILITY :
      This bug can be reproduced always.

            jdv Jayathirth D V
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: