tags:

views:

2946

answers:

7

I'm having a strange problem, basically in Java Graphics.drawImage() is extremely slow on some computers and faster on others. This isn't related to the computers power either, some weaker computers run it fine while some stronger ones seem to choke up at the drawImage call.

It may or may not be related to the width and height, I have a very, very large width and height defined (something like 5000 by 2500). I wouldn't think it's the issue except like I said it runs in real time speed on some computers and slower on others and doesn't seem to be tied to the computers relative power.

Both computers have the same version of Java, both use Vista. One has a 1.83ghz Core 2 Duo with 1gb RAM and onboard graphics (runs everything fine), the other has a 2.53 ghz core 2 duo with a 9600GS (latest nVidia drivers) and 4gb of RAM and it literally chugs on the drawImage call.

Any ideas?

edit: ok this is really wierd, I'm drawing the image to a window in Swing, now when I resize the window and make it really small the image gets scaled down too and it becomes small. Suddenly everything runs smoothly, when I scale it back up to the size it was before it's still running smoothly!

It also has multiple monitor issues, if I do the resize trick to make it run faster on one monitor then scroll it over to another monitor when more than half of the window is in the new monitor it starts chugging again. I have to resize the window again to small then back to its original size to get back the speed.

If I do the resize trick on one monitor, move it over to the other it of course chugs, but if I return it back to the original monitor on which I did the resize trick it works 100%

If I have two swing windows open (displaying the same image) they both run slow, but if I do the resize trick on one window they both start running smoothly (however this isn't always the case).

*when I say resize the window I mean make it as small as possible to the point the image can't actually be seen.

Could this be a bug in Java maybe?

+1  A: 

There are several things that could influence performance here:

  • Available RAM
  • CPU speed
  • Graphic card (onboard or seperate)
  • Graphic driver
  • Java version
  • Used video mode (resolution, bitdepth, acceleration support)

EDIT: Having a look at the edited question, I'd propose to check if the 9600GS system has the newest NVIDIA drivers installed. I recently installed a driver for an Intel onboard graphics card that replaced the generic Windows driver and made moving windows, watching videos, browsing etc. a lot faster.

All the other specs look good. Perhaps Java doesn't detect the 9600GS and doesn't use hardware acceleration, but I doubt this.

Also check the OS configuration. On Windows, you can turn off hardware acceleration for debugging purposes.

Of course the best way to handle this would be to change your code - resize the image or split it up into chunks as DNS proposed. You'll never be able to see the whole image as it is on the screen.

schnaader
One computer is old, we're talking really old and the other is new and high end, it has better CPU, RAM, graphics but the same version of Java.Also I might have been wrong with the 50,000x25,000, it's actually 5000x2500.
+2  A: 

How are you judging the computers' power? A 50x25 K 32-bit image takes more than 4.5 GB RAM to hold in memory (50000 * 25000 * 4 bytes). If one computer has more RAM than another, that can make a huge difference in speed, because it won't have to swap to disk as often. You should consider grabbing subsections of the image and working with those, instead of the whole thing.

Edit: Are you using the latest Java & graphics drivers? If your image is only 5Kx2.5K, the only thing I can think of is that it's doing it without any hardware acceleration.

DNS
no I meant 5000x2000, I did find the 50000x20000 number rather large then realized I was putting an extra 0 at the end of the numbers, I might be slowly going blind or something.
A: 

What is different, what is the same ? "Some computers" is too vague - are the operating systems the same ? Same versions ? Are your Java installations all the same version ?

Morendil
I edited my original post for correctness and details
A: 

Check the screen settings. My bet is that pixel depth is different on the two systems, and that the slow one has an odd pixel depth related to the image object you are trying to display.

Thorbjørn Ravn Andersen
A: 

Since Java uses OpenGL to do 2D drawing, the performance of your app will be affected by the OpenGL performance of the graphics chip in the respective computer. Support for OpenGL is dwindling in the 3D industry, which means that (ironically) newer chips may be slower at OpenGL rendering than older ones - not only due to hardware but also drivers.

Ian Kemp
+2  A: 

If you are using sun's java try some of the following system properties, either as command line parameters or the first lines in main

sun.java2d.opengl=true //force ogl
sun.java2d.ddscale=true //only when using direct3d
sun.java2d.translaccel=true //only when using direct3d

more flags can be viewed at this page Look at sun.java2d.trace which can allow you to

determine the source of less-than-desirable graphics performance

KitsuneYMG
+3  A: 

Performance of writing an image to a screen is very much affected by the format in which the image is stored. If the format is the same as the screen memory wants then it can be very fast; if it is not then a conversion must be done, sometimes pixel by pixel, which is very slow.

If you have any control over how the image is stored, you should store it in a format that the screen is looking for. Here is some sample code:

    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getDefaultScreenDevice();
    GraphicsConfiguration config = device.getDefaultConfiguration();
    BufferedImage buffy = config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);

If you are going to draw the image many times it may be worth converting to a compatible format even if it came in some other format.

Drawing an image will also be slower if you are transforming it as you draw, which the 'resizing' part of your description makes me think you might be.

DJClayworth