loading image broken in 5.0?

D

dar7yl

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>
 
A

Andrew Thompson

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
 
A

Andrew Thompson

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.
 
A

Andrew Thompson

..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.

* Which -also- links to the code ( of course ;).
 
D

dar7yl

Andrey Kuznetsov said:
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.
 
D

dar7yl

Andrew Thompson said:
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.
 
L

Larry Barowski

dar7yl said:
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.
 
D

dar7yl

Larry Barowski" said:
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
 
L

Larry Barowski

dar7yl said:
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.
 
A

Andrey Kuznetsov

if you send me the image I can try to find the problem.
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();
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top