loading image broken in 5.0?

Discussion in 'Java' started by dar7yl, Jan 10, 2005.

  1. dar7yl

    dar7yl Guest

    I recently upgraded my personal computer to jre 1.5.0_01-b08 (I was forced
    into it, honest).
    I was previously running 1.4.2_05-b04.

    The problem is that Image Icon loading in applets no longer seems to be
    working.
    The icon (from a .gif) appears to be loaded, but it does not display,
    and it's <width,height> resolve to (-1,-1)

    It still works in 1.4, but doesn't work in 5.0/1.5/whatever.

    <code>
    class MyApp extends JApplet
    {
    JFrame display = new JFrame("Test load Icons");
    JLabel label = new JLabel();
    //...
    public int init()
    {
    ImageIcon icon = null;

    display.add(label);

    java.net.URL imgURL = MyApp.class.getResource( "Images/myicon.gif");
    if ( imgURL != null )
    {
    system.out.println("opening image icon url: " + imgURL );
    icon = new ImageIcon( imgURL, "my own, personal icon");
    }

    if (icon != null)
    {
    label.setIcon( icon );
    int width= icon.getIconWidth();
    int height = icon.getIconHeight();
    system.out.println("Icon: " + icon + ", width: " + width + ",
    height: " + height );

    display.setSize( width+100, height+100 );
    }
    display.show();
    }
    //...
    }
    </code>

    <trace>
    opening image icon url: http://wherever.com/test.jar!/Images/myicon.gif
    Icon: my own, personal icon, width: -1, height: -1
    </trace>
     
    dar7yl, Jan 10, 2005
    #1
    1. Advertising

  2. > <trace>
    > opening image icon url: http://wherever.com/test.jar!/Images/myicon.gif
    > Icon: my own, personal icon, width: -1, height: -1
    > </trace>

    this link seems to broken, is it real or fake link?
    may be your test.jar is gone.

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
     
    Andrey Kuznetsov, Jan 10, 2005
    #2
    1. Advertising

  3. On Mon, 10 Jan 2005 01:18:05 GMT, dar7yl wrote:

    > sub: loading image broken in 5.0?


    Almost certainly not. I have image projects that run successfully
    under 1.4 or 1.5. Further, 'images will not load' is not one of those
    things that would tend to slip through testing unnoticed.

    > <trace>
    > opening image icon url: http://wherever.com/test.jar!/Images/myicon.gif
    > Icon: my own, personal icon, width: -1, height: -1
    > </trace>


    The 1.5 JRE might be loading and initialising faster, before the image
    is fully loaded. If that is the case, adding a MediaTracker should help.

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Jan 10, 2005
    #3
  4. On Mon, 10 Jan 2005 09:40:55 +0100, Andrey Kuznetsov wrote:

    >> <trace>
    >> opening image icon url: http://wherever.com/test.jar!/Images/myicon.gif
    >> Icon: my own, personal icon, width: -1, height: -1
    >> </trace>

    > this link seems to broken, is it real or fake link?


    'wherever' looks to be an indication of 'fake'

    > may be your test.jar is gone.


    ...but I was about to suggest the OP post an actual link to the
    web-page with the applet instead of code and vague descriptions.

    It is much faster for us to check the basic facts, and helps
    avoid any confusion.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Jan 10, 2005
    #4
  5. Andrew Thompson, Jan 10, 2005
    #5
  6. dar7yl

    dar7yl Guest

    "Andrey Kuznetsov" <> wrote in message
    news:crtf2i$m1b$...
    >> <trace>
    >> opening image icon url: http://wherever.com/test.jar!/Images/myicon.gif

    > this link seems to broken, is it real or fake link?
    > may be your test.jar is gone.


    of course, it's a fake link. Sorry, I don't want lurkers messing around my
    stuff.
    regards,
    Dar7yl.
     
    dar7yl, Jan 10, 2005
    #6
  7. dar7yl

    dar7yl Guest

    "Andrew Thompson" <> wrote in message
    news:...
    >
    > The 1.5 JRE might be loading and initialising faster, before the image
    > is fully loaded. If that is the case, adding a MediaTracker should help.


    I was under the impression that ImageIcon() uses a MediaTracker in it's
    implementation.
    But you might have something there. If the image hasn't been loaded yet,
    that would hexplain things.
    I traced icon.getImageLoadStatus(), which returned 4 (ERRORED).
    Ok, how do I find out what the error condition was so I can fix it? (nothing
    in the docs)
    BTW, it's not the jar, because it exhibits the same problem when expanded.

    regards,
    Dar7yl.
     
    dar7yl, Jan 10, 2005
    #7
  8. >>> <trace>
    >>> opening image icon url: http://wherever.com/test.jar!/Images/myicon.gif

    >> this link seems to broken, is it real or fake link?
    >> may be your test.jar is gone.

    >
    > of course, it's a fake link. Sorry, I don't want lurkers messing around
    > my stuff.


    I was in doubt because http://wherewer.com exists.

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
     
    Andrey Kuznetsov, Jan 10, 2005
    #8
  9. "dar7yl" <> wrote in message
    news:EDzEd.16503$06.8215@clgrps12...
    > "Andrew Thompson" <> wrote in message
    > news:...
    > >
    > > The 1.5 JRE might be loading and initialising faster, before the image
    > > is fully loaded. If that is the case, adding a MediaTracker should

    help.
    >
    > I was under the impression that ImageIcon() uses a MediaTracker in it's
    > implementation.
    > But you might have something there. If the image hasn't been loaded yet,
    > that would hexplain things.
    > I traced icon.getImageLoadStatus(), which returned 4 (ERRORED).
    > Ok, how do I find out what the error condition was so I can fix it?

    (nothing
    > in the docs)
    > BTW, it's not the jar, because it exhibits the same problem when expanded.


    It's possible that the gif is invalid in a way that previous
    versions of Java ignored. Try loading and saving it in a
    few different image editors.
     
    Larry Barowski, Jan 11, 2005
    #9
  10. dar7yl

    dar7yl Guest

    "Larry Barowski" wrote:
    > It's possible that the gif is invalid in a way that previous
    > versions of Java ignored. Try loading and saving it in a
    > few different image editors.


    Ok, but I really want to know what the error condition was, and why it
    affects 5.0 and not 1.4 and below. That to me is a bug (maintainability of
    backwards compatability with previous versions).

    My biggest beef is that the sophomoric idiot who invented the library
    couldn't be bothered to implement some sort of error trace so that we can
    find the problem and fix it within the development environment.

    regards,
    Dar7yl
     
    dar7yl, Jan 11, 2005
    #10
  11. Andrew Thompson, Jan 11, 2005
    #11
  12. >> It's possible that the gif is invalid in a way that previous
    >> versions of Java ignored. Try loading and saving it in a
    >> few different image editors.

    > Ok, but I really want to know what the error condition was


    if you send me the image I can try to find the problem.
    my email can be found here: http://reader.imagero.com/mailto.php

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
     
    Andrey Kuznetsov, Jan 11, 2005
    #12
  13. "dar7yl" <> wrote in message
    news:yMOEd.67354$nN6.22585@edtnps84...
    > "Larry Barowski" wrote:
    > > It's possible that the gif is invalid in a way that previous
    > > versions of Java ignored. Try loading and saving it in a
    > > few different image editors.

    >
    > Ok, but I really want to know what the error condition was, and why it
    > affects 5.0 and not 1.4 and below. That to me is a bug (maintainability

    of
    > backwards compatability with previous versions).
    >
    > My biggest beef is that the sophomoric idiot who invented the library
    > couldn't be bothered to implement some sort of error trace so that we can
    > find the problem and fix it within the development environment.


    True, there doesn't seem to be any way to trace the error from
    ImageIcon.

    Try this:

    Iterator image_readers = ImageIO.getImageReadersBySuffix("gif");
    ImageReader ir = (ImageReader)image_readers.next();
    try {
    ir.setInput(new FileImageInputStream(new File("somefile.gif")));
    ir.read(0); }
    catch(Throwable t) {
    System.out.println("Error " + t);
    }

    The errors are sometimes useful and sometimes not - for example
    an ArrayIndexOutOfBoundsException doesn't tell you much.
     
    Larry Barowski, Jan 11, 2005
    #13
  14. >> if you send me the image I can try to find the problem.
    >> my email can be found here: http://reader.imagero.com/mailto.php
    >>

    >Thanks, Andrey. Here's (some of) the images that don't work under 5.0.


    Hi Dar7yl,

    I tried your images with all JDKs (inclusive 1.5.0_01)
    and they was ok.
    I tried both ways - ImageIcon and MediaTracker.

    here is my code (you may comment/uncomment appropriate parts):

    import javax.swing.*;
    import java.io.File;
    import java.io.IOException;
    import java.awt.*;

    public class Test {
    static String directory = "C:\\Dokumente und
    Einstellungen\\ak\\Desktop";
    static String filename0 = "JupiterIcon.GIF";
    static String filename1 = "Empire Grain B.GIF";

    public static void main(String[] args) throws IOException {
    File f = new File(directory, filename0);
    // File f = new File(directory, filename1);
    final Image img =
    Toolkit.getDefaultToolkit().createImage(f.getAbsolutePath());
    Frame frame = new Frame("gif test");
    System.out.println("using imageIcon");

    ImageIcon icon = new ImageIcon(img);
    // MediaTracker mt = new MediaTracker(frame);
    // mt.addImage(img, 0);
    // try {
    // mt.waitForID(0);
    // }
    // catch (InterruptedException ex) {
    // ex.printStackTrace();
    // }
    Panel panel = new Panel() {
    public void paint(Graphics g) {
    super.paint(g);
    g.drawImage(img, 0, 0, null);
    }
    };
    frame.add(panel);
    frame.setBounds(100,100,300,300);
    frame.show();
    }
    }

    --
    Andrey Kuznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
    http://jgui.imagero.com Java GUI components and utilities
     
    Andrey Kuznetsov, Jan 12, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven D'Aprano

    Why are "broken iterators" broken?

    Steven D'Aprano, Sep 21, 2008, in forum: Python
    Replies:
    8
    Views:
    684
  2. Cameron Simpson

    Re: Why are "broken iterators" broken?

    Cameron Simpson, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    608
    Cameron Simpson
    Sep 22, 2008
  3. Fredrik Lundh

    Re: Why are "broken iterators" broken?

    Fredrik Lundh, Sep 22, 2008, in forum: Python
    Replies:
    0
    Views:
    623
    Fredrik Lundh
    Sep 22, 2008
  4. Replies:
    4
    Views:
    331
  5. edfialk
    Replies:
    0
    Views:
    205
    edfialk
    May 10, 2007
Loading...

Share This Page