Noticed something funny today - well, it would be funny, except I've
already wasted several hours on it.

Once upon a time, I was able to arbitrarily scale my Images when I
painted them with Graphics.drawImage(image, x, y, width, height,
observer). Now I'm finding that isn't so. 

The little snippet below illustrates this. It takes three arguments: an
image file name, a width and a height. Image not incuded, I'm afraid. I
recommend the following:

$ javac ImageScaling.java
$ file someimage.gif 
someimage.gif: GIF image data, version 89a, 400 x 400,
$ java ImageScaling someimage.gif 400 400

i.e., compile and try it with the normal image size arguments to prove
it works normally. Then try shrinking it:

$ java ImageScaling someimage.gif 200 200 
$ java ImageScaling someimage.gif 100 100
$ java ImageScaling someimage.gif 50 50
$ java ImageScaling someimage.gif 25 25

This should all work; at least it did for me.

Now try blowing it up:

$ java ImageScaling someimage.gif 800 800 
$ java ImageScaling someimage.gif 1600 1600 

For some reason, this doesn't work in general - the image isn't drawn at
all. I've had no success even just doubling both width and height.
Smaller images do seem to take longer to blow up, but I can't get
800x800 out of a 100x100 image.

I've ran back to 1.1.6, but my 1.1.5 and earlier were all libc5 and
don't work any more. This runs the same on all 1.1.6 as far as I can
tell.

So am I insane, or is this some new bug? The feature that depends on
this was working in our last version of our product; I just rewrote it
for swing and was reimplementing the feature under swing when I ran into
this all of a sudden. At first I thought it was Swing-related, but as
you can see I was able to demonstrate it using only AWT components.

- - - - - - - - - - - - - ->8 - - - - - - - - - - - - - - - - - 
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Frame;

public class ImageScaling extends Canvas {
        private Image image;
        private int width, height;

        public static void main(String[] argv) {
                String imagename = argv[0];
                int width = (new Integer(argv[1])).intValue();
                int height = (new Integer(argv[2])).intValue();

                ImageScaling scaler = new ImageScaling(imagename, width, height);
                Frame framed = new Frame("Image Scaling example");
                framed.add(scaler, "Center");
                framed.setSize(640, 480);
                framed.show();
                }

        public ImageScaling(String imagename, int width, int height) {
                image = getToolkit().getImage(imagename);
                this.width = width;
                this.height = height;
                }
        
        public void paint(Graphics g) {
                g.drawImage(image, 0, 0, width, height, this);
                }

}

- - - - - - - - - - - - - ->8 - - - - - - - - - - - - - - - - - 
-- 

Paul Reavis                                      [EMAIL PROTECTED]
Design Lead
Partner Software, Inc.                        http://www.partnersoft.com

Reply via email to