How do i scale a buffered image? basically i’m searhcing for a function like the following
scaleImage( BufferedImage src, BufferedImage dst, float ratioX, float ratioY)
tia
Paul
How do i scale a buffered image? basically i’m searhcing for a function like the following
scaleImage( BufferedImage src, BufferedImage dst, float ratioX, float ratioY)
tia
Paul
won’t
dst.getGraphics().drawImage( src, 0, 0, (int)(src * ratioX), (int)(src * ratioY), null );
fulfill your need?
What pepe said should do it. If you want it, you can specify some ‘renderingHints’ (search google) such that the scaling operation is performed with a desired degree of efficiency contra quality. Specifically, look at RenderingHints that have to do with INTERPOLATION.
Or since BufferedImage extends Image, you can just call getScaledInstance(int width, int height, int hints); This also depends on the control that you want. There are a lot more RenderingHints options with pepe’s method.
Please don’t use getScaledInstance(). It’s old, and in many cases much slower than the scaling variants of drawImage(). We’d like to either a) reimplement getScaledInstance() so that it doesn’t suck, but there a number of subtle issues that prevent us at the moment, b) add docs to getScaledInstance() discussing the limitations and point to the drawImage() methods, or c) deprecate it entirely, but this is really unlikely to happen.
Chris
Java 2D Team
RenderingHints does not seem to work for me when I use Graphics.drawImage(…). What do I need to set for best quality with drawImage(…) using scaling?
okay i found this on the net, using an affinetransform and an affinetransform operation, but this is incredibly slow when using large images. ( i need to rescale so the image fit in a power of 2 texture, with the same dimensions used by jogl.
Is it normal that it’s so slow coz i think it only involves a scale matrix to do this, ( takes several seconds with a 1280 * 1000 ) picture
on my pIv 3.4 ghz
kingaschi, I have used
KEY- and VALUE_INTERPOLATION_BILINEAR .
Several seconds seem to be too slow. Which java version?
Could you run with -Dsun.java2d.trace=log and post the output when it scales
the images?
Dmitri