Hi.

I am writing an Applet for viewing large (~2600x3500) tiff files. Here is my 
scaling method

public static BufferedImage getScaledInstance( Image img, int targetWidth,
            int targetHeight, Object hint, boolean higherQuality ) {

        long startTime = System.currentTimeMillis();

        BufferedImage ret = null;
        int w, h;
        if (higherQuality) {
            // Use multi-step technique: start with original size, then
            // scale down in multiple passes with drawImage()
            // until the target size is reached
            w = img.getWidth(null);
            h = img.getHeight(null);
        } else {
            // Use one-step technique: scale directly from original
            // size to target size with a single drawImage() call
            w = targetWidth;
            h = targetHeight;
        }

        do {
            if (higherQuality && w > targetWidth) {
                w /= 2;
                if (w < targetWidth) {
                    w = targetWidth;
                }
            }

            if (higherQuality && h > targetHeight) {
                h /= 2;
                if (h < targetHeight) {
                    h = targetHeight;
                }
            }

            ret = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = ret.createGraphics();
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);

            g2.drawImage(img, 0, 0, w, h, null);
            g2.dispose();

        } while (w != targetWidth || h != targetHeight);

        long stopTime = System.currentTimeMillis();
        long runTime = stopTime - startTime;
        System.out
                .println("Run time: getScaledInstance() : " + runTime + " ms");

        return ret;
    }


If I use ImageIO to read the tiff file as a BufferedImage and pass it as a 
source image to method, It takes ~1600ms to scale it down to ~800x600. But if I 
use Jimi.getImage() and get the image as a java.awt.Image type and pass in 
method, it takes ~800ms to scale.


I wonder why bufferedimage is slower. I want to use ImageIO instead of Jimi as 
it supports more formats, it comes with default Jdk and Jimi seems old 
framework. But as I said, if I use ImageIO, I get a BufferedImage that scales 
slower.

And I wonder if I learn and use VolatileImage, should it be faster or I will no 
effect for my purpose.

Thanks and sorry for my bad english.
[Message sent by forum member 'rahjman' (rahjman)]

http://forums.java.net/jive/thread.jspa?messageID=299820

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to