This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes Width and height of Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Width and height of Image" Watch "Width and height of Image" New topic

Width and height of Image

hasan wasif2k1

Joined: Jan 13, 2001
Posts: 26
Trying to retreive image width and height but no success.
A Code is here but with errors. Pls help soon.
<%@ page import="java.awt.*" %>
<%@ page import="java.awt.image.*" %>
Image img=Toolkit.getDefaultToolkit().getImage("a.jpg");
int w=img.getWidth();
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13018
Images are loaded by a separate Thread so you can not immediately get the width and height. A MediaTracker will help you there.
You can NOT put an image into a page from inside a JSP, all you can do is write the code that makes the browser load the image - look at the html tag for <img> - it takes a URL because the browser starts a separate Thread to load the image.

author of:
I agree. Here's the link:
subject: Width and height of Image
It's not a secret anymore!