|
import java.awt.*; import java.awt.event.*; import java.util.Locale; public class GetImageSize extends Frame { Image image; String imageName = "photo.jpg"; int width,height; public GetImageSize() { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); } public void paint(Graphics g) { Toolkit tool = Toolkit.getDefaultToolkit(); image = tool.getImage(imageName); width=image.getWidth(this); height=image.getHeight(this); this.setSize(width+20,height+80 ); g.drawImage(image, 10, 30, this); g.setColor(new Color(180,0,0)); g.setFont(new Font("Times New Roman",1, 40)); g.drawString(imageName.toUpperCase(Locale.ENGLISH), width/2-50, 70); g.setFont(new Font("Times New Roman",1, 16)); g.drawString("Image Size : "+width+ "*"+height,10,height+60); } public static void main(String args[]) throws Exception { GetImageSize image = new GetImageSize(); image.setVisible(true); image.setLocation(200, 100); } } |

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Get Image Size Example
Post your Comment