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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Image Size 
 

This Java awt (Abstract Windowing Toolkit) tutorial describes about the image size. This is an actual representation of object. Simply, it helps us to feel associated with an object on the frame. Some images are either 'literal' images that are unequally

 

Image Size

                         

This Java awt (Abstract Windowing Toolkit) tutorial describes about the image size. This is an actual representation of object. Simply, it helps us to feel associated with an object on the frame. Some images are either 'literal' images that are unequally create and involve little or no extension of the various meaning of the words that are used to express them or 'figurative' images that do not follow the literal meaning of the worlds completely.

Description of program:  

This program helps you in setting an image and getting the size of its. For setting an image on the frame, you will need an image that have to be added in the MediaTracker object with the help of addImage() method. After adding you will get the size of image (width and height) through the getWidth() and getHeight() method. Here you will see the frame's size are arranged according to the size of image. You will try and get it.

Description of code:

Toolkit():
This is the constructor of Toolkit class that is the abstract super class of all exact implementation of awt. The various components are bounded by subclass of Toolkit to a particular native toolkit implementations.

getDefaultToolkit():
This method returns the default toolkit and if could not be found it then it will thrown by the AWTError.

getImage(String file_name):
This method gets pixels data from the given file name that has the extension either GIF, JPEG or PNG and returns an image in pixels. It takes string type file name that is the name of an image.

MediaTracker():
This is the constructor of MediaTracker class that is a utility class for tracking the status of a number of media objects that include an audio clips as well as images but only images are supported in current time.

waitForID(int id):
This method is used to start the loading all images with the help of media tracker to specified identifier that are given by user.

getWidth():
This method returns the width of displaying images in pixels.

getHeight():
This method returns the height of displaying images in pixels.

Here is the code of program:

import java.awt.*;
import java.awt.event.*;

public class ImageSize extends Frame{
  Image image;
  public static void main(String[] args) {
    try{
      new ImageSize();
    }
    catch(InterruptedException e){}
  }
  public ImageSize() throws InterruptedException{
    Toolkit tool = Toolkit.getDefaultToolkit();
    image = tool.getImage("1.gif");
    MediaTracker mTracker = new MediaTracker(this);
    mTracker.addImage(image,1);
    mTracker.waitForID(1);
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    System.out.println("The width of image: " + width);
    System.out.println("The height of image: " + height);
    setSize(width, height);
    setTitle("Image Size Example!");
    addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent we){
        System.exit(0);
      }
    });
    setVisible(true);
  }
  public void paint(Graphics g){
    g.drawImage(image,0,0,null);
  }
}

Download this example.

Output of program:

Size of an image:

C:\vinod\awt1>javac ImageSize.java

C:\vinod\awt1>java ImageSize
The width of image: 300
The height of image: 224

                         

» View all related tutorials
Related Tags: c class make method sed boolean value ole set oo frame if boo to ram bool argument e il not

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.