Very slow image operation
Hello,
I have a strange problem.
Some of my images areVERY slow to load, scale... (any image operation).
I have those 2 images :
http://193.252.5.30/tmp/cat1.jpg (25Ko : 295x551 pixels)
http://193.252.5.30/tmp/cat2.jpg (24Ko : 295x551 pixels)
I wrote a little program which load and scale the image.
Here is the result :
cat1.jpg
Time to load image : 171 ms.
Time to scale image : 157 ms.
cat2.jpg
Time to load image : 1157 ms.
Time to scale image : 2578 ms.
How can this huge difference explained ?
Thanks for your help.
The program :
publicclass Test
{
privatefinalstatic BufferedImage scale(BufferedImage source,float scaleFactor)
{
int width = Math.round(source.getWidth()*scaleFactor);
int height = Math.round(source.getHeight()*scaleFactor);
ColorModel dstCM = source.getColorModel();
BufferedImage dst =new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(width, height), dstCM.isAlphaPremultiplied(),null);
Image scaledImage = source.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);
Graphics2D g = dst.createGraphics();
g.drawImage(source, 0, 0, width, height,null);
g.dispose();
return dst;
}
publicstaticvoid main(String[] args)throws IOException
{
String imagePath ="cat1.jpg";
//String imagePath = "cat2.jpg";
long t1 = System.currentTimeMillis();
BufferedImage image = ImageIO.read(new File(imagePath));
long t2 = System.currentTimeMillis();
System.out.println("Time to load image : " + (t2-t1) +" ms.");
t1 = System.currentTimeMillis();
image = scale(image, 0.2f);
t2 = System.currentTimeMillis();
System.out.println("Time to scale image : " + (t2-t1) +" ms.");
}
}

