ImageIcon displaying problem

Hi,

In my application I load a 4275*2672 JPEG file using ImageIcon and displaying it using a self defined JLabel (with scrollbars) on a JFrame. When i display the picture there is no problem at first, but after a repaint (i scroll down, resize the window, etc.) the image blurs.

I know for sure it is not because of the large picture, because i had the same problem with smaller pictures (and i had no problem with larger pictures). There is no problem viewing it if i navigate to the file with explorer. So the image is fine to.

Maybe i should use a different image class, like bufferedImage, or manual paint using Graphics2d.paintImage.

I would also like to be able to zoom in / out eventually although that is not my biggest concern.

Any thoughts on this?

Thank you.

[813 byte] By [Jakob_Da] at [2007-10-3 2:41:52]
# 1

WELL....................

I'm not sure what you're using, and what you mean by blurring.

BUT, if you mean that the image simply leaves a trail after going off its edge, that could be because you're not clearing the buffer...

If it is blurring while the whole image fits on the screen then you could have alpha set to some semi-transparent value...

AK47_prga at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 2

Thank you for answering

Yes, the image leaves a trail.

I added code to clear the buffer using flush() after every scroll step. But as you can imagine this is horrible, everytime you scroll the image it reloads completely wich in this case takes 1 second.

I only have this problem a few times with certain generated images (the images are graphs), why dont i have this problem everytime?

Is there any other way doing this?

Jakob_Da at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 3

Why do you reload the image each time?

Just have it loaded once and display whenever...

But if you meant it takes 1 second to DISPLAY it. Then I can answer one of two things...

1) You're screwed

2) Split it into tiles...

Answer 2 means, take the picture and separate it into sub pieces. Store each sub piece as an image object in some class that you make. Mesh the tiles together using some algorithm, should'nt be too hard...

Also, what's the big picture for?

AK47_prga at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 4

Well yes it then takes 1sec to display it.

1) not an option ;)

2) thought about it, but didnt do it because i had a lot larger pictures that worked perfectly.

I generate these pictures using http://www.graphviz.org/ and create huge pictures which i then display on a JFrame

Thanks.

Jakob_Da at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 5
Can I see your code?I'm no pro but I guess I could find something...
AK47_prga at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 6

public class ScrollablePicture extends JLabel implements Scrollable,

MouseMotionListener {

private int maxUnitIncrement = 1;

private boolean missingPicture = false;

private ImageIcon image;

public ScrollablePicture(ImageIcon i, int m) {

super(i);

this.image = i;

if (i == null) {

missingPicture = true;

setText("No picture found.");

setHorizontalAlignment(CENTER);

setOpaque(true);

setBackground(Color.white);

}

maxUnitIncrement = m;

setAutoscrolls(true);

addMouseMotionListener(this);

}

this is the constructor for the ScrollablePicture class, which i took from an sun tutorial.

ImageIcon imageIcon = new ImageIcon(fileName);

image = new ScrollablePicture(imageIcon, 50);

JScrollPane pane = new JScrollPane(image);

this.add(pane);

The generating part of the image is loads of code, which i could display but would be meaningless since it has proved to be correct in other situations

Jakob_Da at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 7
i advise to make your own scrollableimage class... it'll take less time for it to work, rather than spend so much time trying to figure out why this doesn't work... If you say no to that.. i'll just go do some research for ya...
AK47_prga at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...
# 8
Hm ok, ill try that. Although i still find this a very strange problem!Thank you for helping me! You can get the 5 dukes for trying ;)anyone else that has any idea on how to solve this?
Jakob_Da at 2007-7-14 19:40:34 > top of Java-index,Security,Cryptography...