Tue Nov 11, 2008 8:04 pm
import java.awt.*;
import javax.swing.*;
public class ImageScale extends JFrame {
Image image;
Insets insets;
public ImageScale() {
super("Show Image Scales");
ImageIcon imageIcon = new ImageIcon("image4.jpg");
image = imageIcon.getImage();
}
public void paint(Graphics g) {
super.paint(g);
if (insets == null) {
insets = getInsets();
}
g.drawImage(image, insets.left, insets.top, this);
}
public void scale() {
reset();
Image img = image;
image = img.getScaledInstance(250, -1, Image.SCALE_FAST);
repaint();
reset();
image = img.getScaledInstance(300, -1, Image.SCALE_SMOOTH);
repaint();
reset();
image = img.getScaledInstance(450, -1, Image.SCALE_REPLICATE);
repaint();
reset();
image = img.getScaledInstance(400, -1, Image.SCALE_DEFAULT);
repaint();
reset();
image = img.getScaledInstance(350, -1, Image.SCALE_AREA_AVERAGING);
repaint();
reset();
System.exit(0);
}
private void reset() {
try {
Thread.sleep(3000);
} catch (Exception e) {}
}
public static void main(String args[]) {
ImageScale imgScale = new ImageScale();
imgScale.setSize(400, 200);
imgScale.show();
imgScale.scale();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.