Problem with ImageIO.read and ImageReader JPG colors are distorted/wrong

(Using JDK 1.5)
ImageIO incorrectly reads some jpg images.
I have a jpg image that, when read by the ImageIO api, all the colors become reddish.
        try
            java.awt.image.BufferedImage bi = javax.imageio.ImageIO.read( new java.io.File("javabug.jpg") );
            javax.imageio.ImageIO.write( bi, "jpg", new java.io.File("badcolors.jpg") );
            javax.imageio.ImageIO.write( bi, "png", new java.io.File("badcolors.png") );
        catch ( java.io.IOException ioe )
            ioe.printStackTrace();
        }Why is this happening??? My guess is there is a problem with the ImageIO.read ?
the jpg can be downloaded at http://www.alwaysvip.com/javabug.jpg
<BufferedImage@11faace: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@1ebbfde transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 1691 height = 1269 #numDataElements 3 dataOff[0] = 2>
I have even tried creating a new buffered image but still have the same problem:
(suggested by http://forum.java.sun.com/thread.jspa?forumID=20&threadID=665585) "Java Forums - ImageIO: scaling and then saving to JPEG yields wrong colors"
        try
            java.awt.image.BufferedImage bi = javax.imageio.ImageIO.read( new java.io.File("javabug.jpg") );
            java.awt.image.BufferedImage out = new java.awt.image.BufferedImage( bi.getWidth(), bi.getHeight(), java.awt.image.BufferedImage.TYPE_INT_RGB );
            java.awt.Graphics2D g = out.createGraphics();
            g.drawRenderedImage(bi, null);
            g.dispose();
            javax.imageio.ImageIO.write( out, "jpg", new java.io.File("badcolors.jpg") );
        catch ( java.io.IOException ioe )
            ioe.printStackTrace();
        }I have used the following which works but does not use the ImageIO api. However, I tried using the ImageIO to write and it worked for writing which leads me to believe there is a problem with the reader.
(suggested by http://developers.sun.com/solaris/tech_topics/java/articles/awt.html "Server-Side AWT")
        try
            java.awt.Image image = new javax.swing.ImageIcon(java.awt.Toolkit.getDefaultToolkit().getImage("javabug.jpg")).getImage();
            java.awt.image.BufferedImage bufferedImage = new java.awt.image.BufferedImage( image.getWidth( null ), image.getHeight( null ), java.awt.image.BufferedImage.TYPE_INT_RGB );
            java.awt.Graphics g = bufferedImage.createGraphics();
            g.setColor( java.awt.Color.white );
            g.fillRect( 0, 0, image.getWidth( null ), image.getHeight( null ) );
            g.drawImage( image, 0, 0, null );
            g.dispose();
            com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder( new java.io.FileOutputStream( "goodcolors.jpg" ) );
            encoder.encode( bufferedImage );
            javax.imageio.ImageIO.write( bufferedImage, "jpg", new java.io.File("goodiocolors.jpg") );
            javax.imageio.ImageIO.write( bufferedImage, "png", new java.io.File("goodiocolors.png") );
        catch ( java.io.IOException ioe )
            ioe.printStackTrace();
        }BTW, the following does not work either:
            java.util.Iterator readers = javax.imageio.ImageIO.getImageReadersByFormatName( "jpg" );
            javax.imageio.ImageReader reader = ( javax.imageio.ImageReader ) readers.next();
            javax.imageio.stream.ImageInputStream iis = javax.imageio.ImageIO.createImageInputStream( new java.io.File("javabug.jpg") );
            reader.setInput( iis, true );
            java.awt.image.BufferedImage bufferedImage = reader.read( 0 );

I figured out the problem. It was an actual BUG in the JDK!
The code failed with the following JDKs:
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode)
The code ran sucessful with this JDK:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
If you are using the ImageIO classes, I highly suggest you upgrade to the latest JDK.
Best,
Scott

Similar Messages

  • Problem with ImageIO.read and ImageReader GIF becomes dark

    I am having problems with certain GIF images loading completely dark. I previously had problems with certain JPGs colors being distorted http://forum.java.sun.com/thread.jspa?threadID=713164&tstart=0. This was a problem in an old JDK.
    Here is the code:
                java.awt.image.BufferedImage bufferedImage = javax.imageio.ImageIO.read( new java.io.File("javabug.gif") );
                System.out.println( bufferedImage );
                javax.imageio.ImageIO.write( bufferedImage, "jpg", new java.io.File("badcolors.jpg") );
                javax.imageio.ImageIO.write( bufferedImage, "png", new java.io.File("badcolors.png") );BufferedImage Read is:
    BufferedImage@337838: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@119cca4 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 1536 height = 1152 #numDataElements 3 dataOff[0] = 2
    Here is the GIF
    http://www.alwaysvip.com/javabug.gif
    I am using jdk1.5.0_06
    If I use java.awt.Toolkit.getDefaultToolkit().getImage instead of ImageIO.read, the problem no longer exists.
            java.awt.Image image = java.awt.Toolkit.getDefaultToolkit().getImage( file.toURL() );
            java.awt.MediaTracker mediaTracker = new java.awt.MediaTracker( new java.awt.Container() );
            mediaTracker.addImage( image, 0 );
            mediaTracker.waitForID( 0 );
            java.awt.image.BufferedImage bufferedImage = new java.awt.image.BufferedImage( image.getWidth( null ), image.getHeight( null ), java.awt.image.BufferedImage.TYPE_INT_RGB );
            java.awt.Graphics g = bufferedImage.createGraphics();
            g.setColor( java.awt.Color.white );
            g.fillRect( 0, 0, image.getWidth( null ), image.getHeight( null ) );
            g.drawImage( image, 0, 0, null );
            g.dispose();
            javax.imageio.ImageIO.write( bufferedImage, "jpg", new java.io.File("goodcolors.jpg") );
            javax.imageio.ImageIO.write( bufferedImage, "png", new java.io.File("goodcolors.png") );BufferedImage Read is:
    BufferedImage@1bf216a: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 1536 height = 1152 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0
    Is this another bug in the JDK? Is there a possible workaround where I can still use ImageIO.read?

    I figured out the problem. It was an actual BUG in the JDK!
    The code failed with the following JDKs:
    java version "1.5.0_01"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
    Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
    java version "1.5.0_03"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
    Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode)
    The code ran sucessful with this JDK:
    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
    If you are using the ImageIO classes, I highly suggest you upgrade to the latest JDK.
    Best,
    Scott

  • Problem with Adobe Reader and IE

    I'm using Vista Home Premium and IE9 with the latest Reader available.  Starting yesterday, I cannot read PDF files on the web.  This is a new problem.  I tried to download newer versions of IE and the Reader, but both tell me I've got the newest versions I can use.
    I have no problem with Firefox.  Just IE.  I prefer using IE.  Can someone guide me -- without using technical language.  Many thanks!!

    Thanks for your input.  I opened the standalone Adobe Reader X, clicked Edit, Preferences, Security, Advanced Preferences.  Then clicked each of the 3 tabs on top, but nothing looked like "Protected Mode."
    Then I went back and clicked Security (Enhanced) and unchecked Enable Enhanced Security.  Tested this change, but I still get the gray screen and messages:  "A problem has caused IE to close."  "A problem with this website has caused IE to close and re-open the tab."  I then went back and re-checked Enable Enhanced Security.
    I should mention that I have used this particular website for about 10 years and never had a problem.  But I now have the same problem with any online PDF that I try to open using IE.
    Can you think of anything else?  If not, here's my plan of attack.  Please let me know if you think it will work.
    1)  Copy over all my favorite sites from IE to Firefox.  (I've already started doing that.)
    2)  Uninstall IE and re-install it.
    3)  If I still have a problem, uninstall Adobe Reader and re-install it.
    Do you think this will do the job if all else fails?
    Many, many thanks for the time you have put into this.

  • Problem with ImageIO.read()

    I have a problem with loading picture from file to variable Image img. Function ImageIO.read(fileIn) return always null pointer (whereas fileIn!=null). I'm using j2sdk-1_4_2_0. The same problem problem is in WindowsXP SP2 and Fedora 3 64bit.
    Here is code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    import java.awt.image.*;
    import javax.imageio.*;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import java.io.*;
    public class Converter extends JPanel implements ActionListener {
    JPanel mainPanel, info1Panel,info2Panel,convertionPanel, fSizePanel,displayPanel;
    JCheckBox enableConvertion;
    JButton selectFile,doIt,close;
    JRadioButton size1,size2;
    ButtonGroup sizeGroup;
    ImageIcon imagePrev;
    JRadioButton[] convertion = new JRadioButton[2];
    Image img;
    JLabel previewLabel;
    JFileChooser fc;
    File fileIn = new File("10.jpg");
    File fileOut;
    public Converter() {
    // Tworzenie paneli
    mainPanel=new JPanel();
    mainPanel.setLayout(null);
    info1Panel=new JPanel();
    info2Panel=new JPanel();
    convertionPanel=new JPanel(new BorderLayout());
    fSizePanel=new JPanel();
    displayPanel= new JPanel();
    //Tworzenie pozostalych elementow
    enableConvertion = new JCheckBox("Enable JPG <-> PNG");
    selectFile = new JButton("Select File");
    doIt = new JButton("Do it!");
    close= new JButton("Close");
    fc = new JFileChooser();
    size1 = new JRadioButton("The same resolution");
    size2= new JRadioButton("Resize image to target size of file");
    JLabel previewLabel = new JLabel();
    ButtonGroup sizeGroup = new ButtonGroup();
    imagePrev= new ImageIcon();
    // proba ulozenia elementow na ramce
    Insets insets = mainPanel.getInsets();
    Dimension size = selectFile.getPreferredSize();
    selectFile.setBounds(15 + insets.left, 15 + insets.top,size.width, size.height);
    doIt.setBounds(15 + insets.left,15+5+ insets.top+size.height,size.width, size.height);
    close.setBounds(15+insets.left,15+2*(5+size.height)+insets.top,size.width,size.height);
    convertionPanel.setBounds(10,150,250,90);
    convertionPanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Convertion"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    info1Panel.setBounds(150,10,200,140);
    info1Panel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Source File Information"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    info2Panel.setBounds(360,10,200,140);
    info2Panel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Target File Information"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    fSizePanel.setBounds(10, 250, 250, 90);
    fSizePanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("File size"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    fSizePanel.setLayout(new GridLayout(2,0));
    displayPanel.setBounds(270,150,290,190);
    displayPanel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createTitledBorder("Display"),
    BorderFactory.createEmptyBorder(0,5,5,5)));
    previewLabel.setHorizontalAlignment(JLabel.CENTER);
    previewLabel.setVerticalAlignment(JLabel.CENTER);
    previewLabel.setVerticalTextPosition(JLabel.CENTER);
    previewLabel.setHorizontalTextPosition(JLabel.CENTER);
    previewLabel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createLoweredBevelBorder(),
    BorderFactory.createEmptyBorder(5,5,5,5)));
    previewLabel.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createEmptyBorder(0,0,10,0),
    previewLabel.getBorder()));
    size1.setSelected(true);
    mainPanel.add(info1Panel);
    mainPanel.add(info2Panel);
    mainPanel.add(convertionPanel);
    mainPanel.add(fSizePanel);
    mainPanel.add(displayPanel);
    //osadzamy w odpowiednich panelach elementy
    mainPanel.add(selectFile);
    mainPanel.add(doIt);
    mainPanel.add(close);
    sizeGroup.add(size1);
    sizeGroup.add(size2);
    fSizePanel.add(size1);
    fSizePanel.add(size2);
    displayPanel.add(previewLabel);
    convertionPanel.add(enableConvertion);
    selectFile.addActionListener(this);
    public void actionPerformed(ActionEvent e) {
    int returnVal = fc.showOpenDialog(Converter.this);
    if (returnVal == JFileChooser.APPROVE_OPTION)
    File fileIn = fc.getSelectedFile();
    JFrame frame1=new JFrame();
    JOptionPane.showMessageDialog(frame1, fileIn.getName());
    if(fileIn==null)
    JFrame frame2 = new JFrame();
    JOptionPane.showMessageDialog(frame2,"FileIN==NULL");
    //############## PROBLEM IS HERE ###########################
    try
    Image img=ImageIO.read(fileIn); // HERE IS THE PROBLEM: img==NULL
    // WHERAS fileIn!=NULL
    }catch (IOException event){}
    if (img==null)
    JFrame frame2 = new JFrame();
    JOptionPane.showMessageDialog(frame2,"img==NULL");
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create a new instance of LunarPhases.
    Converter conv = new Converter();
    //Create and set up the window.
    JFrame convFrame = new JFrame("Conversion JPG <-> PNG");
    convFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    convFrame.setContentPane(conv.mainPanel);
    Insets insets = convFrame.getInsets();
    convFrame.setSize(600 + insets.left + insets.right,400+insets.top + insets.bottom);
    convFrame.setVisible(true);
    public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    //############## PROBLEM IS HERE ###########################
    try {
    Image img=ImageIO.read(fileIn); // HERE IS THE PROBLEM: img==NULL
    // WHERAS fileIn!=NULL
    } catch (IOException event){}
    if (img==null) {
        JFrame frame2 = new JFrame();
        JOptionPane.showMessageDialog(frame2,"img==NULL");
    }1. Please use [code] tags when posting code -- it makes the code more readable.
    2. When posting code, post a minimal example program. You could have filtered
    out all the extraneous GUI code, for example. Remember: the shorter the code, the
    more likely it is a forum member will read it! Posting long runs of code only
    hurts yourself.
    3. All that being said, your problem is a simple oversight: notice that the
    variable "img" in your try block is a local variable, not the field named "img"
    than you test after the try block.
    You should have written:
    try {
        img=ImageIO.read(fileIn);
    } catch (IOException event){
        e.printStackTrace();
    }

  • Problems with Adobe Reader and Flash Player

    I had an Adobe update last Monday and, ever since then, I can't view documents (eg credit card statements) on screen and sites that I previously visited regularly without problem suddenly say that I need to have Adobe Flash Player installed. I've downloaded Adobe Flash Player and it says it's installed correctly but when I return to the site, it still says I need Adobe Flash Player. I've also tried doing an uninstall first and then an instal but the same thing happens. I've run disk first aid and it found a problem with the Head which it fixed but I still can't open documents using Adobe in Safari. Adobe Plug ins tells me that the Internet Access plug in is not loaded but when I ran 'repair Adobe Reader installation", it said there were no missing components detected and repair was not needed. I don't know if it's relevant but I've been having problems with Safari for several weeks, quitting 3 or 4 times a day, mainly when I'm switching from Safari to another programme such as Entourage or Excel.
    Message was edited by: Aileen2

    Hi Carolyn
    I don't think I made it clear on the original post that I'm having problems with both Adobe Reader AND Adobe Flash Player. Unfortunately, all the Adobe Reader sites are confidential so I can't give you an illustration on that but for the Adobe Flash Player, try www.jacquielawson.com/ - you can preview cards without being signed in. With the Adobe Reader problems, I get a picture of a blank 'piece of paper' with a small blue square in the top right hand corner that has a white question mark inside it. The first time this happened to me, I was on the UK Inland Revenue site trying to print out some end of year forms. I phoned the Revenue's helpline and they said to try doing a 'save as' to my desktop. It seemed bizarre - saving a blank piece of paper - but lo and behold, when I opened it on my desktop, the forms appeared exactly as normal. However, I've since tried this 'save as' technique with my credit card statement and I still get a blank piece of paper with a blue square and white question mark when I open the desktop copy.
    Thanks for your help and patience. I really appreciate it.
    Aileen

  • Problem With File Reading And Sorting

    I'm having problems with a particular task. Here is what I have to do:
    Write a program which reads 100 integers from a file. Store these integers
    in an array in the order in whcih they are read. Print them to the screen.
    Sort the integers in place using bubble sort. Print the sorted array to the
    screen. Now implement the sieve of Eratosthenes to place all prime numbers
    in an ArrayList. Print that list to the screen.
    Here is the code I have so far:
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add();
            catch(Exception e)
    This is the file reading part I have done but it doesn't recognise the line numbers.add() . It brings up the error - 'Cannot resolve symbol - method add(). Thats the first problem I have, can anyone see any way to fix it and to achieve the task. Also can someone help with the structure of a bubble sort method and a sieve of Eratosthenes method as I have no clue whatsoever. Any help will be greatly appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Ok, I've done that but I'm having another problem. When I'm printing an output to the screen, it prints 100 lines of integers and not 1 line of 100 integers. Can you see the problem in the code that is doing this?
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add(temp);
                    System.out.println(numbers);
            catch(Exception e)
    }

  • Problem with air read and write smb shared directory of file

    hi, everyone.
    I'm want to access smb directory of file,And to read and
    write operation, I would like to ask how I should do?
    Thanks!

    You can't access any OS facility nor execute arbitrary command.
    So the best solution is to mount samba directory BEFORE run your AIR application; you eventually can create a script that mount samba (and asks password) and then run you AIR application.
    see
    http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-conc ept/
    for a more complex solution.

  • Problem with serial read and write-unab​le to refresh the port number

    I use the advanced serail write and read example. Build the application, copy the application to another laptop with labview run time engine 2009 installed. And I connect my serial device via a serial to usb adaptor. The problem is that VISA source number is always com1, even I refresh it. But in my case the device via adpator should be com5. I can get the hyperterminal working using com5. Something must be wrong. The strange thing is that there are three laptops, I did the same processdure with each one, one of them are working, the other two won't. Anybody came cross same problems before? Many thanks.

    Hi,
    I think you didn't have installed the Visa Run time engine on this computer.
    best regards,
    V-F

  • Problems with PDFs, Reader, and Printing

    My web application exports PDF files using SQL Server Reporting Services. The exported PDF files are version 1.3 (supposedly compatible with Adobe Acrobat version 4 and higher). Previously I used Crystal Reports which output PDF files as version 1.2.
    This switch to 1.3 has caused havoc with SOME of my ASP (application service provider) customers because if they use Adobe Reader 8 to print the PDFs then they get obscure printing errors (the header of one page prints and then a printed error message of ERROR: Undefined COMMAND: 1b&) with certain Xerox workgroup printers (and not with most other printers). If they use Adobe Reader 7, then they have no problems at all with ANY of the printers.
    So, at its core, this is a problem somewhere with Adobe PDF files, PDF versions, printers and their drivers, and the latest version of Adobe Reader (8.1.2). I would like to think that the latest version of any software should work better and my customers won't have to go back to Adobe Reader 7.0 to print things.
    Is this a bug in Adobe Reader 8.1.2? What are the workarounds?
    Thanks for any help.

    Not sure, but have you tried this patch: http://helpx.adobe.com/acrobat/kb/pdf-wont-print-reader-10.html ?

  • Intermittent problem with ImageIO reading BMP: Empty Region

    I am using imageIO to read in a bmp file, like this:
          ImageInputStream is = ImageIO.createImageInputStream(imgURL.openStream());
          Iterator<ImageReader> rdrs = ImageIO.getImageReaders(is);
          if (rdrs.hasNext()) {
            ImageReader r = rdrs.next();
            r.setInput(is);
            result = r.read(0);
          }(I use the same code to read in a whole bunch of images of various kinds.) In development, I got an empty image, so I added a wait:
    MediaTracker mt = new MediaTracker(new MyObserver());
        mt.addImage(iconImage, 0);
        try {
          mt.waitForID(0);
        } catch (InterruptedException e) {
        }which seemed to work fine. Except that sometimes, not always, I got a crash:
    java.lang.IllegalArgumentException: Empty region!
         at javax.imageio.ImageReader.computeRegions(Unknown Source)
         at com.sun.imageio.plugins.wbmp.WBMPImageReader.read(Unknown Source)
         at javax.imageio.ImageReader.read(Unknown Source)I got that sometimes in development, but once I produced the production version it started happening all the time!
    Anyone have an idea what's going on??

    That was very close to correct. It seems that the WBMP reader mucks up the input stream before the .ico reader can get to it. The .ico plugin, which is available at [http://www.vdburgh.net/2/f/files/ICOReader/ ] puts out a very nice error message to that effect and suggest using a fresh input stream. So this:
          ImageInputStream is = ImageIO.createImageInputStream(imgURL.openStream());
          Iterator<ImageReader> rdrs = ImageIO.getImageReaders(is);
          while (rdrs.hasNext()) {
            ImageReader r = rdrs.next();
            try {
              r.setInput(is);
              result = r.read(0);
              return result;
            } catch (IllegalArgumentException e) {
              System.out.printf("Bad Image:%s%n", e.getMessage());
              is = ImageIO.createImageInputStream(imgURL.openStream());
          }Does the trick! (So far :)

  • Problem with PDF Reader and Create PDF plugins

    Hello,
    I use Internet Explorer Nine. The Adobe PDF Reader plugin disappeared from my browser. When I look at the listing of my add-ons, Adobe PDF reader appears in the list of all add-ons but not in the list of currently loaded add-ons. I have tried reinstalling Adobe Reader X and adding the FileOpen.api file to the plug-ins subfolder of the reader folder of the Reader 10.0 program files folder to no avail. How did the plugin disappear from by browser? How can I reinstall the plugin? Would reinstalling Adobe Acrobat Standard XI help?
    I was once able, on every website, to turn in a portion of the text and/or pictures on the website into a PDF file by right-clicking and clicking on "Convert to Adobe PDF." Now, I can perform this action only on certain websites. When I cannot perform the action correctly, the entire webpage is converted into a PDF file. What could be causing the malfunction? How can I fix it?
    Thank your for your help. Have an excellent day.

    I&m not quite sure I understand your problem.  You have Adobe PDF Reader under All Add-ons; is it enabled?
    Can you view any PDFs in Internet Explorer?

  • As we are having a problem explicit with Adobe Reader 11.0.07, we are interested in news and dates for coming updates to Adobe Reader. Can I find information about this anywhere ?

    As we are having a problem explicit with Adobe Reader 11.0.07, we are interested in news and dates for coming updates to Adobe Reader. Can I find information about this anywhere ?

    Hello Claus,
    you could have a look here: http://helpx.adobe.com/security/products/flash-player/apsb14-13.html  and in german language http://www.chip.de/downloads/Adobe-Reader_12998358.html
    In all These cases Google could be "your friend".
    Hans-Günter

  • ImageIO: scaling and then saving to JPEG yields wrong colors

    Hi,
    when saving a scaled image to JPEG the colors are wrong (not just inverted) when viewing the file in an external viewer (e.g. Windows Image Viewer or The GIMP). Here's the example code:
    public class Main {
         public static void main(String[] args) {
              if (args.length < 2) {
                   System.out.println("Usage: app [input] [output]");
                   return;
              try {
                   BufferedImage image = ImageIO.read (new File(args[0]));
                   AffineTransform xform = new AffineTransform();
                   xform.scale(0.5, 0.5);
                   AffineTransformOp op = new AffineTransformOp (xform, AffineTransformOp.TYPE_BILINEAR);
                   BufferedImage out = op.filter(image,null);
                   ImageIO.write(out, "jpg", new File(args[1]));
    /* The following ImageViewer is a JComponent displaying
    the buffered image - commented out for simplicity */
                   ImageViewer imageViewer = new ImageViewer();
                   imageViewer.setImage (ImageIO.read (new File(args[1])));
                   imageViewer.setVisible (true);
              catch (Exception ex) {
                   ex.printStackTrace();
    Observations:
    * viewing this JPEG in an external viewer displays the colors wrong, blue becomes reddish, skin color becomes brown, blue becomes greenish etc.
    * when I skip the transformation and simply write the input 'image' instead the colors look perfect in an external viewer!
    BufferedImage image = ImageIO.read (new File(args[0]));
    ImageIO.write (image, "jpg", new File(args[1]));
    * when I do the scale transformation but store as PNG instead the image looks perfect in external viewers!
    BufferedImage out = op.filter(image,null);
    ImageIO.write(out, "png", new File(args[1]));
    * viewing the scaled JPEG image with The GIMP produces "more intense" (but still wrong) colors than when viewing with the Windows Image Viewer - I suspect that the JPEG doesn't produce plain RGB values when decompressed (another color space used then sRGB? double instead of int values?)
    * Loading the saved image and display it in a JComponent shows the image fine:
    class ViewComponent extends JComponent
         private Image image;
         protected void paintComponent( Graphics g )
              if ( image != null )
    // image looks okay!
                   g.drawImage( image, 0, 0, this );
         public void setImage( BufferedImage newImage )
              image = newImage;
              if ( image != null )
                   repaint();
    * Note that I've tried several input image formats (PNG, JPEG) and made sure that they were stored as RGB (not CMYK or the like).
    * Someone else already mentioned that the RGB values as read from an JPG image are wrong, but no answer in this thread - might be connected with this problem: http://forum.java.sun.com/thread.jspa?forumID=20&threadID=612542
    * I tried the jdk1.5.0_01 and jdk1.5.0_04 on Windows XP.
    Any suggestions? Is this a bug in the ImageIO jpeg plugin? What am I doing wrong? Better try something like JAI or JIMI? I'd rather not...
    Thanks a lot! Oliver
    p.s. also posted to comp.lang.java.programmers today...

    Try using TYPE_NEAREST_NEIGHBOR
    rather than
    TYPE_BILINEARI was a bit quick with saying that this doesn't work - I had extended my example code which made it fail (see later), but here's a working version first (note: I use the identity transform only for simplicity and to show that it really doesn't matter whether I scale, rotate or shear)):
    // works, but only for TYPE_NEAREST_NEIGHBOR interpolation
    Image image = ImageIO.read (new File(args[0]));
    AffineTransform xform = new AffineTransform();
    AffineTransformOp op = new AffineTransformOp (xform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    BufferedImage out = op.filter(image, null);
    ImageIO.write(out, "jpg", new File(args[1]));The problem: we restrict ourselves to nearest neighbor interpolation, which is especially visible when scaling up (or rotate, shear).
    Now when I change the following, it doesn't work anymore, the stored image has type=0 instead of 5 then (which obviously doens't work with external viewers):
    // doesn't work, since an extra alpha value is introduced, even
    // for TYPE_NEAREST_NEIGHBOR
    BufferedImage out = op.filter(image, op.createCompatibleDestImage(image, ColorModel.getRGBdefault()));Intuitively I would say that's exactly what I want, and RGB image with data type int (according to JavaDocs). That it has an alpha channel is a plus - or is it?
    I think this extra alpha value is the root of all evil: JPEG doesn't support alpha, but I guess ImageIO still mixes this alpha value somehow into the JPEG data stream - for ImageIO that's not a problem, the JPEG data is decompressed correctly (even though the alpha values have become meaningless then, haven't checked that), but other JPEG viewers can't manage this ARGB format.
    This also explains why writing to PNG worked, since PNG supports alpha channels.
    And obviously an AffineTransformOp silently changes the image format from RGB to ARGB, but only for TYPE_BILINEAR and TYPE_CUBIC, not for TYPE_NEAREST_NEIGHBOR! Even though I can imagine why this is done like this (it's more efficient to calculate with 32 bit ints than with 24 bit packed values, hence the extra alpha byte...) I would at least expect the JPEG writer to ignore this extra alpha value - at least with the default settings and unless otherwise told with extra parameters! Now my code gets unnecessary complicated.
    So how do I scale an image using bilinear (or even bicubic) interpolation, so that it get's displayed properly with external viewers? I found the following code working:
    // works, but I need an extra buffer and draw operation - UGLY
    // and UNNECESSARILY COMPLICATED (in my view)
    BufferedImage image = ImageIO.read (new File(args[0]));
    AffineTransform xform = new AffineTransform();
    AffineTransformOp op = new AffineTransformOp (xform, AffineTransformOp.TYPE_BILINEAR);
    BufferedImage out = op.filter(image, null);
    // create yet another buffer with the proper RGB pixel structure
    // (no alpha), draw transformed image 'out' into this buffer 'out2'          
    BufferedImage out2 = new BufferedImage (out.getWidth(), out.getHeight(),
                                                             BufferedImage.TYPE_INT_RGB);
    Graphics2D g = out2.createGraphics();
    g.drawRenderedImage(out, null);
    ImageIO.write(out2, "jpg", args[1]);This is already way more complicated than the initial code - left alone that I need to create an extra image buffer, just to get rid of the alpha channel and do an extra drawing.
    I've also tried to supply a BufferedImage as 2nd argument to the filter op to avoid the above:
    ICC_ColorSpace (iccColorSpace = new ICC_ColorSpace (ICC_Profile.getInstance(ColorSpace.CS_sRGB)
    BufferedImage out = op.filter(image, op.createCompatibleDestImage(image, new DirectColorModel (iccColorSpace), 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000, false, DataBuffer.TYPE_INT)));  But then the filter operation failed ("Unable to transform src image") and I was beaten by the sheer possibilities of color spaces, ICC profiles, so I quickly gave up... and hey, I "just" want to load, scale and save to JPG!
    The last option was getting a JPEG writer and its ImageWriteParam, trying to set the output image type:
    iwparam.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));But again I failed, the resulting image type was still type=0 (and not 5). So I gave up, realising that the Java API is still overly complex and "too design-patterned" for simple tasks :(
    If anyone has still a good idea how to get rid of the alpha channel when writing to JPEG in a simple way (apart from creating an extra buffer as above, which works for me now...)... you're very welcome to enlighten me ;)
    Cheers, Oliver
    p.s. Jim, I will assign you the "DukeDollars", since your hint was somewhat correct :)

  • Problems with .ARW files and auto toning

    problems with .ARW files and auto toning
    let me try to explain this because this has happened in past and never found a way to resolve but i lived with it
    now that I have a Sony A7R the problem is more serious
    Firstly i take pride it making the picture happen all in camera, i use DRO lvl 5 to get enough light, like when i'm shooting at dusk. DRO its like doing HDR but in a single file, it lightens the darks. in my camera i'm happy with results
    but when I upload them to lightroom, they come out near black.
    allow me to explain
    lets say I import 100 images
    i double check my preferences and everything is UNCHECKED when it comes to importing options, there is no auto toning, nothing.
    as the images import i see a preview in the thumbnail which looks fine.
    i double click on one to enlarge it, hence leave grid view.
    for a brief 1 or 2 seconds, i see the full image in all its glory but than lightroom does something funny, it darkens the image
    one by one as it inspects each image, if it was a DRO image it makes it too dark.
    to make this clear, the image is perfect as it was in the beginning but after a few seconds lightroom for some reason thinks it needs to correct it.
    how to prevent lightroom from doing this, i want the image exactly as it is, why must lightroom apply a correction>?
    i think it has to do something with interpreting the raw file and lightroom applies its own algorithm.
    but here is what i dont get.....before lightroom makes the change i'm able to witness the picture exactly as it was taken and want it unchanged..
    now i have to tweak each file or find a profile for it which is added work.
    any ideas how to prevent lightroom from ruining my images and just leave them as they were when first detected...
    there are 2 phases...one is when it originally imports and they look fine
    second is scanning each image and applying some kind of toning which darkens it too much.
    thanks for the help

    sorry thats the auto reply message from yahoo email.
    i've disabled it now
    thing is, there is no DRO jpg to download from the camera
    its only ARW. so my understanding is when i use DRO setting, the camera makes changes to the ARW than lightroom somehow reads this from the ARW.
    but then sadly reverts it to no DRO settings.
    because i notice if i take normal picture in raw mode its dark but if i apply dro to it, it comes out brighter, yet when i d/l the image from camera to lightroom, which is an ARW - there are no jpgs. lightroom decides to mess it up
    so in reality there is no point in using DRO because when i upload it lightroom removes it.
    is there a way to tell lightroom to preserve the jpg preview as it first sees it.
    its just lame, picture appears perfect...than lightroom does something, than bam, its ruined,.
    what do i need to do to prevent lightroom from ruining the image? if it was good in the first place.

  • JPEG file reading wierd bug using ImageIO.read and buffer strategy

    OK I have a slightly (!) bizzare problem. I have a program in Java 1.5.0 /5.0 which is fundamentally using a full screen exclusive mode window to display images loaded from files using ImageIO.read(file). I am getting the graphics context of the buffer strategy used on the FSEM window, and then drawing onto that the image that I have loaded using graphics.drawImage(ImageObj, 0,0, null).
    Now ordinarily this works fine, but I have (after much head scratching) discovered that certain specific jpeg images cause me problems. If I load one of these jpeg images, then it loads in with ImageIO.read fine and I get no errors, but the program locks up on the drawImage(ImageObj, 0,0,null) command in the rendering engine. It doesn't crash, but the CPU usage goes to 100% and stays there, and the method never returns. The image is never displayed on screen obviously, as the program never gets to call bufferStrategy.show() for these images. I have to forcibly terminate the VM to get out of the program.
    Does anyone know what is going on here? Is there some extraneous meta data in the dodgy jpeg files that is doing this? I don't know what 'extras' you can have stored on a jpeg that would cause this behaviour, and I don't know what restrictions there are in the jpeg file reader in Java.
    Its not a major bother to me (now I figured out whats causing it!), as I can just resave a duff jpeg in my image editing app and it will work fine. I just don't know whether I should submit it as a bug or not, and also I thought it would be useful for others to know of this strange behaviour - if I had known about it I would have saved myself about 8 hours!
    Thanks
    Alex

    Oh I forgot to add - I am resizing the images to the screen size using
    Image.getScaledInstance(deviceBounds.width,
    deviceBounds.height,
    Image.SCALE_AREA_AVERAGING);
    and then drawing the scaled image onto the graphics context.

Maybe you are looking for