Hello all
We're running TS671 SP1 and I have a custom servlet to upload an image and create a thumbnail of the uploaded file.
as part of the servlet class, there's a resizeImage function which times out (i'd say after 2 minutes) if the uploaded image is quite big.
The trouble is, when I run the same method on a local file, it runs fast enough (1.3 seconds on a 4Mb image).
Here's what I have isolated as being the offending code:
int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; // check if the image supports transparency
BufferedImage resizedImage = image;
int currentWidth=image.getWidth();
int currentHeight=image.getHeight();
do {
if (currentWidth > (int)rectangleX) {currentWidth /= 2;if (currentWidth < rectangleX) {currentWidth = (int) rectangleX;}}
if (currentHeight > (int)rectangleY) {currentHeight /= 2;if (currentHeight < rectangleY) {currentHeight = (int) rectangleY;}}
System.out.println("currentWidth:" + currentWidth + "; rectangleX:" + (int)rectangleX);
System.out.println("currentHeight:" + currentHeight+ "; rectangleY:" + (int)rectangleY);
//BufferedImage tmp = new BufferedImage(currentWidth, currentHeight, type);
BufferedImage tmp = image.createGraphics().getDeviceConfiguration().createCompatibleImage(currentWidth, currentHeight, type);
Graphics2D g2 = tmp.createGraphics();
/* -->*/ g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
/* --> */ g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.drawImage(resizedImage, 0, 0, currentWidth, currentHeight, null);
g2.dispose();
resizedImage = tmp;
} while (currentWidth != (int)rectangleX || currentHeight != (int)rectangleY);
If I remove the rendering hints, it runs in a similar time as a servlet as it does when I execute it as a local class, but it's makes the thumbnail is somewhat pixelated. If I put them in, it runs like a dog...
Any idea what's causing this? Is it memory related? How can I make it faster whilst still retaining image quality?