Up
Go up to Images

Working with Images


pen.drawImage(  some-image,   x, y ,  width, height );

pen.imgWidth(  some-image )

pen.imgHeight(  some-image )


The pen associated with an applet or subcanvas can be used to manipulate images once they have been loaded. The "drawImage" method is used to display an image in an applet or subcanvas. The first parameter must be the "Image" object to be drawn. If this is the only parameter included, the image will be displayed centered within the applet screen region or subcanvas. If two additional numeric parameter values are provided, they will be treated as the x and y coordinates of the point at which the image's upper left corner should be displayed. If four numeric values are provided as parameters, the first two will be interpreted as coordinates for the image's upper left corner and the last two coordinates will be interpreted as the width and height of the rectangle in which the image should be displayed. Java will resize the image as necessary to fit in this rectangle.

In addition to the "drawImage" primitive, the pen provides two methods, "imgWidth" and "imgHeight" that can be used to determine the size of an image". For example, if one drew an image using the instruction

pen.drawImage(prettypicture, 50, 50);
one could later use the instruction
pen.clearRect(50,50,pen.imgWidth(prettypicture), pen.imgHeight(prettypicture) );
to erase the image from the screen.
Up