wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 12760
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:
subject: Width and height of Image
Similar Threads
Problem in importing html file in jsp
xsl:variable into xsl-fo elements...
trouble with remove item fro shopping cart
Dertermine Image Width & Height
lagging on loading image