File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 13036
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!