We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Image resizing performance (scale or resize)
Page Index Toggle Pages: 1
Image resizing performance (scale or resize) (Read 516 times)
Image resizing performance (scale or resize)
Nov 7th, 2008, 1:51pm
 
How do you resize a image without losing performance?

Sound like a dull question, but if you resize dynamically a image by changing it's width() and height() the applet just run really slowly.

I found resize() and scale() but I don't know if I will get the same performance issues. Re-writting all my code using rezise without knowing made me post here.

cheers
Re: Image resizing performance (scale or resize)
Reply #1 - Nov 7th, 2008, 2:30pm
 
I did a test with resize(). The problem is that you can't keep on scaling down and scaling up otherwise you lose image quality ( like in photoshop ).

resize() is really just to resize a image to a smaller size.

As for scale() I feel that it's going to give the same low performance when scaling a few images at the same times.

What is the best solution for scaling images?
Re: Image resizing performance (scale or resize)
Reply #2 - Nov 7th, 2008, 7:51pm
 
The fastest method is to use the width/height parameters with the image() command.

The second fastest is to use scale().

Using resize() should only be used in cases where you need an image at a specific size, and won't be changing it.
Re: Image resizing performance (scale or resize)
Reply #3 - Nov 7th, 2008, 9:47pm
 
If you resize the image up and down lot of times, maybe you should make the various sizes from the original one (avoiding degradation of quality). And if your image isn't too big and the sizes aren't too numerous, you might want to "cache" the various sizes of images, eg. storing them in an array: there will be only the initial cost of resizing, and on next frames you just pull out the right size.
Re: Image resizing performance (scale or resize)
Reply #4 - Nov 8th, 2008, 1:26pm
 
Humm....

I am using the width() and height() and I am doing something like PhilHo said. Display a image of the initial size, do the transition and then replace with the final size,  but that's the actual process of resizing that slows down the applet.

So if changing the size is not a knowed problem, it must be my code. I am using the png (24) format, could that be part of the problem?

Also I always wonder what was the fastest, image or svg? I know that svg if usefull for having more complex drawing made in illustrator that you can modifies. But I was wondering if displaying image is more demanding then displaying vectors.

Thank you for clarifying the use of scale(), resize() and width/height.
Re: Image resizing performance (scale or resize)
Reply #5 - Nov 8th, 2008, 3:56pm
 
SVG would allow to resize to any size without loss of quality. But in most cases, it would be slower to display, because Processing would need to interpret the SVG commands each time and issue corresponding drawing commands (line, path, etc.).

What size is your image? Is it complex? (photo? drawing?)
Re: Image resizing performance (scale or resize)
Reply #6 - Nov 8th, 2008, 7:06pm
 
The images are really small, less then 10Ko and really not complex. So it's probably my code
Re: Image resizing performance (scale or resize)
Reply #7 - Nov 8th, 2008, 10:22pm
 
There is only one, small, image in my program, but it performs well. See how o make a shape follow a curved path for a moving image. Not sure if that's useful, but just in case...
Page Index Toggle Pages: 1