resizing images is kinda slow

hi, i’m using the following code to resize an image:
http://nopaste.easy-coding.de/?id=91

my machine:
p4 2.8ghz, ht enabled
kernel 2.4.22
jdk 1.4.2_04

unfortunatly, i’ve got the following times:
scaling image: 1280 * 1024 to 640*480
getScaledInstance: 157 msec
drawImage: 53559 msec
dispose: 0 msec
resizing image took: 54880 msec

somehow the drawImage-call is damn slow, is there some other way to do a image-resizing in java in a faster way? or is my code just ‘wrong’?

running that code on windows + jdk 1.5 + p3 500mhz is quite faster (~2sec)

Hey spid. Welcome to the board :wink:

Well, I hadn’t much luck finding anything usefull. However, feel free to try some of those switches:

http://java.sun.com/products/java-media/2D/perf_graphics.html

Try to copy the image retuned from ImageIO to another BufferedImage. Then do the resize in that one instaed.

Try using Toolkit.getDefaultToolkit().getImage() instead it might produce a faster Image. Some images loaded with ImageIO gets some strange pixel format that is a lot slower the non-accelerated normal images. Usually .png with an alpha channel though.

Anyone of those can work. If there’s nothing wrong with your setup of course. :slight_smile:

Cheers,
Mikael

Well, it’s not about acceleration, since it’s a one time operation(*). However, it shouldn’t take 53seconds for drawing one 640x480 image (esp on such hi-end hardware).

(* The default acceleration treshold is 1… so you have to draw it at least twice in order to get it accelerated)

i’ve noticed that if no xserver is running, the code won’t work (exception that no display can be found)
unfortunatly the image-resize has to run in a servlet on a server which has no running xserver (and i can’t decide to start one)

isn’t there another way to resize an image without having a xserver started?

No I didn’t mean to get acceleration but to copy the pixels to another source, on where the pixel data for sure will be ordered in a good way might solve the problem. ImageIO loads certain kinds of image files into some strange pixel format.

However, the problem seems to be related xserver*, something I know absolutely nothing about. :slight_smile:

btw, the ImageIO/png problem is a known one to Sun and they will fix it when time is given.

Cheers,
Mikael

Alright… (I think)

http://java.sun.com/j2se/1.4.2/docs/guide/awt/AWTChanges.html#headless

-Djava.awt.headless=true

is the switch… give it a try :wink:

ah thx, found it too when i googled for ‘java image resizing x server’ :slight_smile:
i’ll just implement it like i already began to and commit everything and try to explain as easy as possible how to start the oracle ias with a vm-argument :wink:

neat link oNyx! It does say that drawing scaled images is faster and more memory efficient now since it no longer draws things to an intermediate buffer. I assume that doesn’t hold true for AffineTransform rendering since profiling my game shows that Graphics2D.drawImage(Image, AffineTransform, ImageObserver) takes up most of the memory of my game :slight_smile: