Java Reference
In-Depth Information
Figure 15.5 Application
ImageScaleFrame
.Top: original size image and a copy that is
linearly scaled by 0.5. Bottom: upper part of the copy scaled by 2.0. The scroll pane can be
used to show the hidden parts
Scaling is done asynchronously. To ensure that the resulting image is only
displayed after it is completed one can again use a media tracker. The following
application
ImageScaleFrame
demonstrates scaling a picture. The main program
loads a photo into the
Image
object
original
. Then two copies
small
and
large
are generated. They are copies of the original scaled by a factor of 0
.
.
0,
respectively. We defined method
scaleImage(image,factor)
which determines
the size of the resulting picture from the dimensions of
image
and the scale factor
factor
. Horizontal and vertical scaling factors are equal; it is left as an exercise
to extend the method to different factors.
ImagePanel
is used to display the three
images. It is embedded into a scroll pane to be able to access all of the pictures.
See Figure 15.5.
5 and 2
File:
its/Images/ImageScaleFrame.java
1.
package
its.Images;
2.
3.
import
its.SimpleFrame.SimpleFrame;
import
java.awt.*;
4.
import
javax.swing.*;
5.
6.
7.
8.
public class
ImageScaleFrame
extends
SimpleFrame {
Search WWH ::
Custom Search