Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Show Image Scale 
 

To show scales of Image, an image is defined inside the class folder and calls the ImageIcon class to return the image.

 

Show Image Scale

                         

This section shows you the scales of image.

To show scales of Image, an image is defined inside the class folder and calls the ImageIcon class to return the image. The Insets class shows the border of a container which specifies the space leave at each of its edges.

The method getScaleInstance() of class Image allows to generate the scales of image. The method drawImage() must know that the scaling has been doing here. There are five hints for scaling the image. The SCALE_DEFAULT shows the default scale of image. The SCALE_FAST  gives priority to speed over smoothness. The SCALE_SMOOTH gives smoothness to speed over speed. The SCALE_REPLICATE  use ReplicateScaleFilter provided by the toolkit. The  SCALE_AREA_AVERAGING use AreaAveragingScalingFilter provided by the toolkit.

Here is the code of ImageScale.java

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(400200);
    imgScale.show();
    imgScale.scale();
  }
}

Output will be displayed as:

We have defined the sleep(3000) method, therefore the scales which are defined in the code will get displayed with the image automatically after the specified interval of time.

Download Source Code

                         

» View all related tutorials
Related Tags: c class orm form io method sed format 2d get ip translation return instance transform show for transformation to draw

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.