Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Width and height of Image

 
hasan wasif2k1
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill

------------------
author of:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic