by Dinesh Thakur Category: AWT and Applets

getWidth and getHeight are predefined abstract methods present in Image class. getWidth method determines the width of an image. getHeight method determines the height of an image. Return type of this two method are int type. Syntax- public abstract int get Width (java.awt.image.    ImageObserver) public abstract int get Height java.awt.image. ImageObserver).

setFont and setColor are predefined abstract methods present in Graphics class. These methods are used to set the font and color of the graphics     context respectively. Syntax-public abstract void setFont (java.awt.Font) public abstract void setColor (java.awt.Color).


Here is the Java Example for GetImageSizeExample:

import java.awt.*;

import java.awt.event.*;
import java.util.Locale;
public class GetImageSizeExample extends Frame
         Image image;
         String Picture = "DineshThakur.jpg";
         String Name = "Dinesh Thakur";
         int width,height;
         public GetImageSizeExample()
         addWindowListener(new WindowAdapter()
                 public void windowClosing(WindowEvent e)
             public void paint(Graphics g)
                    Toolkit tool = Toolkit.getDefaultToolkit();
                     image = tool.getImage(Picture);
                     g.setColor(new Color(0,0,180));
                     g.setFont(new Font("Times New Roman",1,12));
                     g.setFont(new Font("Times new Roman",1,10));
                     g.drawString("My Pic Size: "+width+ "*"+height,135, height+160);
                   public static void main(String args[]) throws Exception
                       GetImageSizeExample GIS = new GetImageSizeExample();
                       GIS.setLocation(200, 100);

find out the image size

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles