Javax.imageio.ImageIO

Hello,
I have recently installed Fedora Core 2 to a dell dimension 8100 and I am trying to compile the program and get this error each time javac runs. error:
Class or interface `javax.imageio.ImageIO' not found in import.
import javax.imageio.ImageIO;
^
Is linux installed with an sdk native to the system? If so how do I uninstall it? Would it conflict if I installed another Java SDK I found that the package jdk 1.5.0_05fcs was installed so I did a rpm -e command on it and reinstalled a fresh copy but this did not help. Thanks!-signol

Ok, I got this error
gcj: unrecognized option `-version'
gcj: no input files
I originally put j2sdk 1.4.2_09 on thinking there was no java to begin with, could this cause some of the errors? Also how would i go about uninstalling the package?-Signol

Similar Messages

  • Problems with javax.imageio.ImageIO (cannot be resolved) *Urgent*

    I was trying to import javax.imageio.ImageIO into my project but it cannot work... I am using Websphere Application 5.1.2 and using JDK 1.4.2_07... I try to import external jar containing javax.image but it still can't solve my problem... So can anyone help me... Thank alot...

    There is no exception, the javax.imageio.ImageIO.read(InputStream input) method simply returns null, indicating that the stream can't be decoded with any of the registered ImageReaders.
    BufferedImage bi = javax.imageio.ImageIO.read(new ByteArrayInputStream(wr2.getData()))
    wr2 is of a class that I have written myself, and the method getData() returns a byte[] array consisting of the bytes previously read from the .gif-file...
    there is nothing wrong with the data stored in the byte[] array, I have even compared it to the original file byte by byte... and it's all the same.
    this works though:
    BufferedImage bi = javax.imageio.ImageIO.read(new FileInputStream("img/iconOnlineDark.gif"))
    Strange problem, in my opinion... but I'm not an expert in streams... so it might not be as strange as it seems to me...? Anyway, I must find a solution to this.
    /erik

  • Javax.imageio.ImageIO: LUT has improper length!

    I have a problem similar to those described in these forum postings:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=404731
    and
    http://forum.java.sun.com/thread.jspa?forumID=256&threadID=510170
    I use the following code:
    String imageURL = "http://a-valid-url";
    java.net.URL url = new java.net.URL(imageURL);
    javax.imageio.stream.ImageInputStream iis =
    javax.imageio.ImageIO.createImageInputStream(url.openStream());
    java.awt.Image img = javax.imageio.ImageIO.read(iis);
    The server at the end of the URL sends back an image in PNG format. The code works fine except on the rare occasions that the image is only black and white, when our old friend the java.lang.IllegalArgumentException is thrown with the message "LUT has improper length!". (I think the exclamation mark on the end is a nice touch.)
    I understand from the other postings that this is a shortcoming in the class I am using. Does anyone know of a way to work around it?
    Thanks in advance!

    I have a problem similar to those described in these forum postings:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=404731
    and
    http://forum.java.sun.com/thread.jspa?forumID=256&threadID=510170
    I use the following code:
    String imageURL = "http://a-valid-url";
    java.net.URL url = new java.net.URL(imageURL);
    javax.imageio.stream.ImageInputStream iis =
    javax.imageio.ImageIO.createImageInputStream(url.openStream());
    java.awt.Image img = javax.imageio.ImageIO.read(iis);
    The server at the end of the URL sends back an image in PNG format. The code works fine except on the rare occasions that the image is only black and white, when our old friend the java.lang.IllegalArgumentException is thrown with the message "LUT has improper length!". (I think the exclamation mark on the end is a nice touch.)
    I understand from the other postings that this is a shortcoming in the class I am using. Does anyone know of a way to work around it?
    Thanks in advance!

  • Using javax.imageio in JSP

    Hi
    I have a simple code snippet that I use to read in JPG/GIF image from a file and create a new image that is upside down . Here is my snippet.
    //create upside down image
    try { 
    String imgPath = "\\images\\AINCC.gif";
    File fImg = new File(imgPath);
    BufferedImage imgREG = ImageIO.read(fImg);
    int iW = imgREG.getWidth(null);
    int iH = imgREG.getHeight(null);
    // Flip the image vertically and horizontally (equivalent to rotating the image 180 degrees)
    AffineTransform tx = AffineTransform.getScaleInstance(-1.0,-1.0);
    tx.translate(-iW, -iH);
    //tx.scale(0.8,0.8);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    BufferedImage imgUSD = op.filter(imgREG, null);
    // write flipped image to a file
    File fUSD = new File("images\\USD_image.tmp");
    ImageIO.write(imgUSD,"jpg",fUSD);
    catch (Exception e) {
    e.printStackTrace();
    If I use this in a stand alone Java app it works fine but it will not work from the JSP page....
    I have updated my server.policy file to give /images directory read, write, delete priviledges and I tried all the variations of the path (relative, absolute, direct....)...
    I get the following error from the server log:
    [#|2004-05-17T13:47:56.173-0400|WARNING|sun-appserver-pe8.0|javax.enterprise.system.stream.err|_ThreadID=11;|
    javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(ImageIO.java:1263)
    at org.apache.jsp.ecards.mailcard_jsp._jspService(mailcard_jsp.java:125)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:141)
    Can someone tell me what am I missing....
    My JSP page is mailcard.jsp and images are under it in the images subdirectory....
    Thanks
    Amir

    Hi,
    Replace the following lines:
    try{
    String imgPath = "\\images\\AINCC.gif";
    with
    <%String contextPath = request.getContextPath();%>
    try{
    String imgPath = <%=contextPath%> + "\\images\\AINCC.gif";
    You may also need to set the web application context root.
    Regards,
    bazooka.

  • ImageIO - javax.imageio.IIOException: Can't get input stream from URL

    Hi,
    I'm developing a program which accesses a given URL of an image and saves it to a file. However when I try this I get the following error:
    javax.imageio.IIOException: Can't get input stream from URL!
         at javax.imageio.ImageIO.read(Unknown Source)
         at ImageSave.main(ImageSave.java:12)
    Caused by: java.net.ConnectException: Connection timed out: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(Unknown Source)
         at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at sun.net.NetworkClient.doConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at java.net.URL.openStream(Unknown Source)
         ... 2 moreThe internet connection I am using uses a proxy server and I think this is where the problem lies. I'm using Eclipse version 3.3 and I've tried changing the network settings to use the proxy's hostname and port but this still isn't working. I've also tried using System.setProperty("http.proxyHost", "hostname") and System.setProperty("http.proxyPort", "port") but that hasn't worked for me either. Below is my class in full.
    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.*;
    import java.net.*;
    public class ImageSave
         public static void main(String args[])
              try {
                   URL url = new URL("http://www.example.com/image.jpg");
                   BufferedImage image = ImageIO.read(url);
                   ImageIO.write(image, "JPG", new File("image.jpg"));
              catch (Exception e) {
                   e.printStackTrace();
    }The error occurs with the line: BufferedImage image = ImageIO.read(url);
    I have tried looking for a way to change how this specific method accesses the internet (e.g: a Proxy parameter with URLConnection) but there doesn't seem to be any.
    Any help or suggestions would be greatly appreciated.
    -Robert

    Ah, that worked fine. I had thought of using that earlier but I was under the impression that the input stream would be HTML rather than an actual image. Not sure why.. Anyway, thanks very much for your help!
    Here is the new code with your suggested revisions and a URLConnection to get the input stream:
    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.*;
    import java.net.*;
    public class ImageSave
        public static void main(String args[])
            try {
                 // This is where you'd define the proxy's host name and port.
                 SocketAddress address = new InetSocketAddress(hostName, port);
                 // Create an HTTP Proxy using the above SocketAddress.
                 Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                 URL url = new URL("www.example.com/image.jpg");
                 // Open a connection to the URL using the proxy information.
                 URLConnection conn = url.openConnection(proxy);
                 InputStream inStream = conn.getInputStream();
                 // BufferedImage image = ImageIO.read(url);
                 // Use the InputStream flavor of ImageIO.read() instead.
                 BufferedImage image = ImageIO.read(inStream);
                 ImageIO.write(image, "JPG", new File("image.jpg"));
            catch (Exception e) {
                 e.printStackTrace();
    }Edited by: Ragnarob on Apr 21, 2009 2:49 AM

  • Javax.imageio.IIOException: Insufficient memory (case 2)         at com.sun

    javax.imageio.IIOException: Insufficient memory (case 2)
    at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(J[BIII[IIIIII[Ljavax.imageio.plugins.jpeg.JPEGQTable;Z[Ljavax.imageio.plugins.jpeg.JPEGHuffmanTable;[Ljavax.imageio.plugins.jpeg.JPEGHuffmanTable;ZZZI[I[I[I[I[IZI)Z(Native Method)
            at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:971)
            at javax.imageio.ImageWriter.write(ImageWriter.java:598)
            at javax.imageio.ImageIO.write(ImageIO.java:1450)
            at javax.imageio.ImageIO.write(ImageIO.java:1515)
            at jsp_servlet._css.__code._jspService(__code.java:145)
            at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
            at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
            at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:230)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    <img border=0 src="code.jsp">
    the content of JSP file about:
    <%@ page import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*"%>
    <%@ page import="java.io.OutputStream"%>
    <%@ page pageEncoding="UTF-8"%>
    <%!Color getRandColor(int fc, int bc) {   
    Random random = new Random();
    if (fc > 255)
    fc = 255;
    if (bc > 255)
    bc = 255;
    int r = fc + random.nextInt(bc - fc);
    int g = fc + random.nextInt(bc - fc);
    int b = fc + random.nextInt(bc - fc);
    return new Color(r, g, b);
    %>
    <%
    try {  
    out.clearBuffer(); // 加上这一句
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    int width = 70, height = 20;
    BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
    OutputStream os = response.getOutputStream();
    Graphics g = image.getGraphics();
    Random random = new Random();
    //设置背景和大小
    g.setColor(getRandColor(200, 250));
    g.fillRect(0, 0, width, height);
    //设置字体和颜色
    g.setFont(new Font("Times New Roman", Font.BOLD, 20));
    g.setColor(getRandColor(120, 200));
    for (int i = 0; i < 50; i++) {   
    int x = random.nextInt(width);
    int y = random.nextInt(height);
    int xl = random.nextInt(5);
    int yl = random.nextInt(5);
    g.drawLine(x, y, x + xl, y + yl);
    String sRand = "";
    for (int i = 0; i < 4; i++) {
    String chose="0123456789";
    String rand = String.valueOf(chose.charAt(random.nextInt(chose.length())));
    sRand += rand;
    g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
    g.drawString(rand, 15 * i + 6, 16);
    session.setAttribute("rand", new String(sRand));
    g.dispose();
    g=null;
    ImageIO.write(image, "JPEG", os);
    os.flush();
    os.close();
    os = null;
    response.flushBuffer();
    out.clear();
    out = pageContext.pushBody();
    } catch (IllegalStateException e) {   
    System.out.println(e.getMessage());
    e.printStackTrace();
    %>

  • Is this a bug in ImageIO?  It gives inconsistent and nasty results

    Hi everyone
    Here's a stumper that I have been having trouble with and finally have a test case to illustrate it. First of all, the code:
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.net.URL;
    import javax.imageio.ImageIO;
    public class PicTest
        public static void main(String[] args) throws Exception
            BufferedImage buf1 = ImageIO.read(new URL("http://www.bestfoto.com/ArchivedPOTD/021606S.jpg"));
            BufferedImage buf2 = ImageIO.read(new URL("http://www.bestfoto.com/ArchivedPOTD/021606O.jpg"));
            ImageIO.write(buf1, "jpg", new File("C:/test1.jpg"));
            ImageIO.write(buf2, "jpg",  new File("C:/test2.jpg"));
    }It's all very simple - we are pulling 2 jpgs from the net and writing them to 2 files. When you run it, test2.jpg is looking very nice. However, test1 is looking horrible and the color is completely off. Anyone know what's going on here? I've seen this on quite a few jpgs now and I'm thinking that there is either a bug in java's JPG codec or the incoming image is somehow corrupted. But, any web browser I try makes the image look fine.
    What gives? Thanks!

    Yes, I think this is a bug in java5 - it cannot write jpegs out because of a missing file in $JAVA_HOME/jre/lib/ccm. The file is called PYCC.pf.
    I forgot that I copied this file from a previous version of the JDK, 1.4x. Maybe this is my problem? But if this file is causing the problem, then taking it out would break the jpeg writer completely.
    Anyone have an idea about this?
    Thanks
    I tried you app in j2se 1.5 and came up with this
    stack trace for both images:
    C:\jexp>java PicTest
    Exception in thread "main"
    java.lang.IllegalArgumentException: Can't load
    standa
    rd profile: PYCC.pf
    at java.awt.color.ICC_Profile$2.run(Unknown
    (Unknown Source)
    at
    at
    at
    at java.security.AccessController.doPrivileged(Native
    Method)
    at
    at
    at
    at
    java.awt.color.ICC_Profile.getStandardProfile(Unknown
    Source)
    at
    at
    at java.awt.color.ICC_Profile.getInstance(Unknown
    wn Source)
    at
    at java.awt.color.ColorSpace.getInstance(Unknown
    known Source)
    at
    at
    at
    at
    com.sun.imageio.plugins.jpeg.JPEG.isNonStandardICC(Unk
    nown Source)
    at
    at
    at
    at
    com.sun.imageio.plugins.jpeg.JPEGMetadata.<init>(Unkno
    wn Source)
    at
    at
    at
    at
    com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(Unk
    nown Source)
    at javax.imageio.ImageWriter.write(Unknown
    (Unknown Source)
    at javax.imageio.ImageIO.write(Unknown
    (Unknown Source)
    at javax.imageio.ImageIO.write(Unknown
    (Unknown Source)
    at PicTest.main(pictest.java:13)It seems to work okay with a "png" extension
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.net.URL;
    import javax.imageio.ImageIO;
    public class PicTest
    public static void main(String[] args) throws
    rows Exception
    BufferedImage buf1 = ImageIO.read(new URL(
    "http://www.bestfoto.com/ArchivedPOTD/021606S.jpg"));
    BufferedImage buf2 = ImageIO.read(new URL(
    "http://www.bestfoto.com/ArchivedPOTD/021606O.jpg"));
    //System.out.println("buf1 type = " +
    pe = " + buf1.getType() + "\n" +
    //                   "buf2 type = " +
    pe = " + buf2.getType());
    // buf1 type = 5
    // buf2 type = 5
    // 5 -> TYPE_3BYTE_BGR
    ImageIO.write(buf1, "png", new
    ng", new File("C:/test1.png"));
    ImageIO.write(buf2, "png", new
    ng", new File("C:/test2.png"));

  • ImageIO, TIFF, and metadata problems

    I'm trying to set some metadata parameters for output of a TIFF image. The problem I had was, the API returns a W3C DOM Node, and since the DOM API is so disgusting, I didn't want to use it directly.
    And naturally, since XPath is supposed to work over a DOM, I thought I could use it as a shortcut.
    Sample program:
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    import javax.imageio.metadata.IIOMetadata;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageTypeSpecifier;
    import javax.imageio.ImageWriteParam;
    import javax.imageio.ImageWriter;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathFactory;
    import org.w3c.dom.Node;
    public class TiffMetadataBug {
        public static void main(String[] args) throws Exception {
            // Test image
            RenderedImage image = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB);
            // Get the default metadata for this kind of image
            ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("TIFF").next();
            ImageWriteParam writeParam = imageWriter.getDefaultWriteParam();
            IIOMetadata metadata = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(image), writeParam);
            // The root metadata node is...
            Node metadataRoot = metadata.getAsTree(metadata.getNativeMetadataFormatName());
            // Output the metadata DOM as XML.
            Transformer identity = TransformerFactory.newInstance().newTransformer();
            System.out.print("XML:");
            identity.transform(new DOMSource(metadataRoot), new StreamResult(System.out));
            System.out.println();
            // Try to match a path into the DOM.
            XPath xPath = XPathFactory.newInstance().newXPath();
            Object result = xPath.evaluate("//TIFFField[@number='282']/TIFFRationals/TIFFRational", metadataRoot, XPathConstants.NODE);
            System.out.println("Result of XPath evaluation: " + result);
    }The first bit of the output was done to see what XPath to use. It contains XML like this:
        <TIFFField number="282" name="XResolution">
            <TIFFRationals>
                <TIFFRational value="1/1"/>
            </TIFFRationals>
        </TIFFField>So my XPath:
    //TIFFField[@number='282']/TIFFRationals/TIFFRationalshould work fine.
    I wonder if this is a bug in the ImageIO metadata code, or if I'm actually doing something wrong here.

    Hi!
    I try to get tiff tags together with their data out of a TIFF-file with the use of DOM. I get problems reading the metadata. How can I read metadata so I can output it like above?
    thanks in advanced.
    Errors I get:
    Exception in thread "main" javax.imageio.IIOException: I/O error reading image metadata!
    at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(Unknown Source)
    at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(Unknown Source)
    at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getImageMetadata(Unknown Source)
    at tiffmetadatabug.Main.main(Main.java:96)
    Caused by: java.io.EOFException
    at javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.java:211)
    at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(ImageInputStreamImpl.java:222)
    at com.sun.media.imageioimpl.plugins.tiff.TIFFIFD.initialize(Unknown Source)
    at com.sun.media.imageioimpl.plugins.tiff.TIFFIFD.initialize(Unknown Source)
    at com.sun.media.imageioimpl.plugins.tiff.TIFFImageMetadata.initializeFromStream(Unknown Source)
    ... 4 more
    Java Result: 1

  • JPEG image decode error with ImageIO.read() method

    Environment: Linux 64-bit, JDK 1.6.0_14 amd64, JAI 1.1.3 amd64
    When I tried to read this image http://farm4.static.flickr.com/3655/3591243423_a258d87ea6.jpg as URL or just the image 3591243423_a258d87ea6.jpg as a local file using ImageIO.read(URL), ImageIO.read(InputStream) or ImageIO.read(String), I got this exception:
    Caused by: java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
            at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:460)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1102)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1070)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:885)
            at javax.imageio.ImageIO.read(ImageIO.java:1422)
            at javax.imageio.ImageIO.read(ImageIO.java:1326)This can be fixed by adding the jai-imageio-1.1 extension( and recent daily builds too). However, that package is not stable, with memory corruption problem from time to time indicated by this:
    *** glibc detected *** /usr/java/jdk1.6.0_13/bin/java: malloc(): memory corruption: 0x000000004d73a3a0 ***Another way to overcome this is using JAI.create("URL", url) or JAI.create("fileload", file) API, which can decode the image but unfortunately the performance is much worse than the ImageIO.read method. So I compromised by using ImageIO.read first and on exception using JAI APIs on the occasional problem image, which looks ugly.
    What would be a better way of handling this?

    Environment: Linux 64-bit, JDK 1.6.0_14 amd64, JAI 1.1.3 amd64
    When I tried to read this image http://farm4.static.flickr.com/3655/3591243423_a258d87ea6.jpg as URL or just the image 3591243423_a258d87ea6.jpg as a local file using ImageIO.read(URL), ImageIO.read(InputStream) or ImageIO.read(String), I got this exception:
    Caused by: java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
            at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:460)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1102)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1070)
            at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:885)
            at javax.imageio.ImageIO.read(ImageIO.java:1422)
            at javax.imageio.ImageIO.read(ImageIO.java:1326)This can be fixed by adding the jai-imageio-1.1 extension( and recent daily builds too). However, that package is not stable, with memory corruption problem from time to time indicated by this:
    *** glibc detected *** /usr/java/jdk1.6.0_13/bin/java: malloc(): memory corruption: 0x000000004d73a3a0 ***Another way to overcome this is using JAI.create("URL", url) or JAI.create("fileload", file) API, which can decode the image but unfortunately the performance is much worse than the ImageIO.read method. So I compromised by using ImageIO.read first and on exception using JAI APIs on the occasional problem image, which looks ugly.
    What would be a better way of handling 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();
    }

  • Jpeg encoding with imageio - pink distortion problem

    Hello, I am using the imageio classes to scale down jpg images (for thumbnails) and write them to a file. On most images, everything works perfectly. On some images, however, the resulting thumbnail image has a strange pink coloration to the whole picture. Does anyone have any ideas as to why this would happen? The code I am using is below. I thank anyone that takes the time to read this and hope someone can help.
    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.image.AffineTransformOp;
    import java.awt.image.BufferedImage;
    import java.awt.image.IndexColorModel;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import javax.imageio.IIOImage;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageTypeSpecifier;
    import javax.imageio.ImageWriteParam;
    import javax.imageio.ImageWriter;
    import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
    import javax.imageio.stream.ImageOutputStream;
    public class ImageResizer
         private static final int THUMBNAIL_MAX = 120;
         private static final int SMALL_MAX = 250;
         private static final int LARGE_MAX = 575;
         private static final int LARGE_THRESHOLD = 425;
         BufferedImage inImage;
         int width;
         int height;
         private static JPEGImageWriteParam params;
         static {
              JPEGImageWriteParam params = new JPEGImageWriteParam(null);
              params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
              params.setCompressionQuality(0.8f);
              params.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
              params.setDestinationType(
                   new ImageTypeSpecifier(IndexColorModel.getRGBdefault(),
                   IndexColorModel.getRGBdefault().createCompatibleSampleModel(16,16)));
         public ImageResizer(byte[] image, long id) throws IOException
              inImage = ImageIO.read(new ByteArrayInputStream(image));
              width = inImage.getWidth(null);
              height = inImage.getHeight(null);
         public void makeSmallImage (File outputFile) throws IOException {
              resizeImage(120, outputFile);
         private void resizeImage (int maxDim, File file) throws IOException {
              double scale = maxDim / (double) height;
              if (width > height) scale = maxDim / (double) width;
              int scaledWidth = (int)(scale * width);
              int scaledHeight = (int)(scale * height);
              BufferedImage outImage = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB);
              AffineTransform xform = AffineTransform.getScaleInstance(scale, scale);
              AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
              // Paint image.
              Graphics2D g2d = outImage.createGraphics();
              g2d.drawImage(inImage, op, 0, 0);
              g2d.dispose();
              // write the image out
              ImageOutputStream ios = null;
              try {
                   ios = ImageIO.createImageOutputStream(file);
                   ImageWriter writer = (ImageWriter) ImageIO.getImageWritersByFormatName("jpg").next();
                   writer.setOutput(ios);
                   writer.write(null, new IIOImage(outImage, null, null), params);
                   writer.dispose();
              catch (IOException e) {
                   System.out.println("cought IOException while writing " +
                   file.getPath());
              finally {
                   if (null != ios) ios.close();
    }

    I am having the same problem with jpegs.
    The strange thing is that this only happends with the same exact code on OS X, while it never happens on any windows machine.
    I have tried using the the ImageIO classes, and a class I got off of this board a while back; however when using this class on an OS X machine, encoding takes a really long time and gives the pink distortion.
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.swing.*;
    import com.sun.image.codec.jpeg.*;
    import java.awt.event.*;
    import java.util.*;
    import java.awt.geom.*;
    public class ImageUtils {
         private static JPEGImageEncoder encoder = null;
         private static FileOutputStream fileStream = null;
         public static BufferedImage createComponentImage(Component component)
              BufferedImage image = (BufferedImage)component.createImage(component.getWidth(),component.getHeight());
              Graphics graphics = image.getGraphics();
              if(graphics != null) { component.paintAll(graphics); }
              return image;
         public static void encodeImage(BufferedImage image, File file) throws IOException
              fileStream = new FileOutputStream(file);
              JPEGEncodeParam encodeParam = JPEGCodec.getDefaultJPEGEncodeParam(image);
              encoder = JPEGCodec.createJPEGEncoder(fileStream);
              encoder.encode(image,encodeParam);
    }use it like this:
    File file = new File("ImageTest.jpg");
    image = ImageUtils.createComponentImage(imageCanvas);
    ImageUtils.encodeImage(image,file);

  • Help ,ImageIO exception to read and write

    Hi,
    I'm dynamically creating image files through screens utility of java(prog name:- Test_ScreenShot.java) and saving
    them in memory sequentially(pic0.jpg,pic1.jpg....etc).Simultaneously I'm accessing the saved files from another
    independent application(Prog name:- Test_Main.java) through piping(executing the application like this "Java
    Test_Screens|Java Test_Main").The application is in infinite loop.I'm using Version JDK 1.5
    I use java Image to read and write image:-
    My application was running well for days.But now I'm getting sudden exceptions.
    I got an exception while trying to save an dynamically generated image file in the local memory using the Image
    class.In brief I'm getting exactly 3 types of exceptions:-
    1)java.io.FileNotFoundException: pic5.jpg (Access is denied)
    2)"Exception in thread "main" java.lang.NullPointerException
    3)Exception in thread "main" com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts with 0xff 0xd9
    Here is the code snippent I wrote:
    /* Robot robot = new Robot();
    BufferedImage image = robot.createScreenCapture(screenRect);
    // save captured image to jpg file
    ImageIO.write(image, "jpg", new File(outFileName));*/
    And here is the exception I am finding (I never found this before, I executed the code many times )
    =====================================================================================================================
    1)Exception Type 1:-
    java.io.FileNotFoundException: pic5.jpg (Access is denied)
    at java.io.RandomAccessFile.open(Native Method)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
    at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:44)
    at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37)
    at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:391)
    at javax.imageio.ImageIO.write(ImageIO.java:1483)
    at Test_ScreenShot.main(Test_ScreenShot.java:112)
    at Test_Main.main(Test_Main.java:466)
    at Test_ScreenShot.main(Test_ScreenShot.java:129)
    2)Exception Type 2:-
    "Exception in thread "main" java.lang.NullPointerException
    at Picture.width(Picture.java:84)
    at Test_Edge_Detector.not_main(Test_Edge_Detector.java:38)
    at Test_Main.main(Test_Main.java:88)"
    ============================================================================================
    Now I tried the following as alternative of ImageIO(from jdk 1.2)
    to read image:-
    FileInputStream fis = new FileInputStream(file);
    JPEGImageDecoder jpeg = JPEGCodec.createJPEGDecoder(fis);
    jpeg.decodeAsBufferedImage();
    fis.close();
    But after running a long time suddenly its giving following exceptions:-
    ==============================================================================================
    Exception Type 3:- )
    Exception in thread "main" com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts with 0xff 0xd9
    at sun.awt.image.codec.JPEGImageDecoderImpl.readJPEGStream(Native Method)
    at sun.awt.image.codec.JPEGImageDecoderImpl.decodeAsBufferedImage(Unknown Source)
    Exception Type 4:- )
    javax.imageio.IIOException: Not a JPEG file: starts with 0xff 0xd9
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(Unknown Source)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(Unknown Source)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(Unknown Source)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(Unknown Source)
    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 Picture.<init>(Picture.java:22)
    at Test_Edge_Detector.not_main(Test_Edge_Detector.java:37)
    at Test_Main.main(Test_Main.java:88)
    Exception in thread "main" java.lang.RuntimeException: Could not open file: pic45.jpg
    at Picture.<init>(Picture.java:27)
    at Test_Edge_Detector.not_main(Test_Edge_Detector.java:37)
    at Test_Main.main(Test_Main.java:88)
    My question is:-
    1)Where is the actual problem?Is it any kind of bug?
    2)I'm using the concept of piping recently to execute the application.Can it be the cause?
         When I googled I found the following informations.There is a bug in ImageIO while trying to write image file.But
    I'm not sure about that it will be relevent here :-
    1)from sun's bug database:-
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6247985
    2)from SUN Developer Forums
    http://forum.java.sun.com/thread.jspa?threadID=768917&messageID=4382833
    3)from Java.NET forum(here they r getting the bug while they r using createScreenCapture() method of robot class,I am
    also using that in my code)
    http://forums.java.net/jive/thread.jspa?messageID=123247
    4)from SUN's archieve
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0207&L=java-imageio-interest&D=0&P=1483
    5)Here is the actual implemetation of ImageIO class.I'm getting error at 391 no. line.
    http://kickjava.com/src/javax/imageio/ImageIO.java.htm
    Thanks And Regards
    Subhadip

    Hello,
    I am writng to ask a doubt I have been encountered. I have an array of Image URL's and I am downloading the images using thses URL for each index. The example for an image URL will be as follows:
    http://www.firstmonday.org/issues/issue6_10/wiggins/google-3oct2001.gifIf the URL is abroken link, I am getting the exception. But if the URL is somewhat hanging (which means when u open that URL in IE or Mozilla, the statuc bar for downloading the image will be hanging).
    So i want to set a timer for every link while downloading. may be 10min. My idea is if in that 10min, if code does not completes downloading the images, then ignore that link and proceed furthur.
    Can u please tell me how to write this.. Please tell me any other idea to tackle this problem.
    Thank you,
    Chaitanya

  • Servlet error from ImageIO

    Does anyone know why the following call to createImageOutputStream works fine in a method called from a stand-alone main(), but generates a servlet error when the same method is called from a jsp using the same parameters?
    try {
    File f = new File(outputFile);
    if (f != null) {
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    No exception is thrown, just a stack dump to stdout.
    Below is a partial stack trace.
    Servlet Error: javax/imageio/ImageIO: java.lang.Exception: javax/imageio/ImageIO
    at programs._testTemplate_jsp_45._jspService(_testTemplate_jsp_45.java:311)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:142)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:323)
    at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:503)
    at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:651)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

    Actually, it does appear that an exception is thrown, but it's not descriptive.

  • Beginner imageIO question (pulling up image over network vs local)

    Greets,
    I am new to java but not too new to programming. I've googled the heck out of this question and checked the java 2D api and haven't had much luck yet. Take a look and let me know what you think:
    I would like to pull up an image file and display it in a jLabel, it works fine if i am pulling up a local file as such:
    BufferedImage img = null;
            try {
                img = ImageIO.read(new File("/home/steve/pic.gif"));
            } catch (IOException e) {
                e.printStackTrace();
            }But what i really want it to do, is pull up a file over the local network, like so:
    BufferedImage img = null;
            try {
                img = ImageIO.read(new File("smb://192.168.1.64/images/pic.gif"));
            } catch (IOException e) {
                e.printStackTrace();
            }However, when i try this second one, i get the following error:
    javax.imageio.IIOException: Can't read input file!
            at javax.imageio.ImageIO.read(ImageIO.java:1275)
            at mypkg.MainForm.load(MainForm.java:143)
            at mypkg.MainForm.<init>(MainForm.java:27)
            at mypkg.MainForm$1.run(MainForm.java:111)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)Can anyone point me in the right direction or give me a code snippet? Much appreciated.

    Paul,
    All definately valid points. I was able to get it to work if i mounted the smb share to my local filesystem but essentially i am trying to make the application portable so i dont have to mount a drive on the target machine (or create a windows drive map, etc). Although read(URL input) isnt exactly what i was looking for, it works good enough and gets the same end result. i just have to copy the image folder and serv it up via apache instead of samba.
    Thanx for your input.

  • Open Tiff image failed with imageio package

    I'm trying to open tiff files with javax.imageio.ImageReader. When openning the image file, "bad.TIF" with the following codes, I got an error. However, I can open the image with "Windows Picture and Fax Viewer" (WPFV). After I opened/saved as File "good.TIF" with WPFX, I can open the image with the progarm. Would someone please help? Thanks.
    Error position is 2
    java.lang.ArrayIndexOutOfBoundsException: 2012
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.nextNBits(TIFFFaxDecompressor.java:1503)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeNextScanline(TIFFFaxDecompressor.java:792)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeT4(TIFFFaxDecompressor.java:1040)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeRaw(TIFFFaxDecompressor.java:677)
         at com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2514)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1137)
         at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1417)
         at javax.imageio.ImageReader.readAll(ImageReader.java:1050)
         at com.rxamerica.image.LoadTiff.main(LoadTiff.java:35)
    import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import javax.imageio.IIOImage;
    import javax.imageio.ImageIO;
    import javax.imageio.ImageReader;
    import javax.imageio.stream.ImageInputStream;
    public class LoadTiff {
    public static void main(String[] args)
    String myDir = "./";
    String testFile1 = myDir + "good.TIF";
    String testFile2 = myDir + "bad.TIF";
    int errorPos = 0;
    ImageInputStream tiffStream = null;
    ImageReader reader;
    try {
    reader = getReader("TIFF");
    IIOImage tiffImage = null;
    errorPos = 1;
    File file = new File(testFile1);
    tiffStream = ImageIO.createImageInputStream(file);
    reader.setInput(tiffStream);
    tiffImage = reader.readAll(0, reader.getDefaultReadParam());
    errorPos = 2;
    file = new File(testFile2);
    tiffStream = ImageIO.createImageInputStream(file);
    reader.setInput(tiffStream);
    tiffImage = reader.readAll(0, reader.getDefaultReadParam());
    catch (Exception e) {
    System.out.println("Error position is " + errorPos);
    e.printStackTrace();
    public static ImageReader getReader(String suffix) throws IOException {
    Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
    if (readers.hasNext())
    return (ImageReader) readers.next();
    else
    throw new IOException("No readers for suffix: " + suffix);
    }

    Can you upload the bad tiff to an [image hosting site|http://www.imagehosting.com/]?
    In general, when you set the input stream on a reader for a second time, it's a good idea to call reset.
    errorPos = 2;
    file = new File(testFile2);
    tiffStream = ImageIO.createImageInputStream(file);
    reader.reset();  <----- this line
    reader.setInput(tiffStream);
    tiffImage = reader.readAll(0, reader.getDefaultReadParam());I don't think that's the source of your problems though. You can add an IIOReadUpdateListener and a IIOReadWarningListener to the reader to see just how far it gets just before the exception is thrown. It may very well just be a badly saved tiff, or it could be a tiff image reader bug.
    Edited by: Maxideon on Jan 19, 2009 7:07 PM
    BTW, which version of JAI-ImageIO are you using?

Maybe you are looking for