Home pageFind It!Contact PJAPJA documentation

PJA

 PJA Toolkit forum

This forum is dedicated to PJA Toolkit.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject Calculate Size of Image

Robert

Member since : Jul 30, 2003
Messages : 1
 Jul 30, 2003 at 4:13 PM
I need to get the size of an Image, to decide if it should be displayd or not. How can I go about it using PJA?

Thanks
Robert

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Aug 5, 2003 at 2:08 PM
You can do it using a class that implements the java.awt.image.ImageObserver interface or by using a MediaTracker instance to synchronize the Image load process and then calling the getHeight and getWidth methods with a null parameter.
For example, this JSP code displays the width and height of an image :
------
<%@ page import="java.awt.*,java.awt.image.*" %>
<% Image im = Toolkit.getDefaultToolkit().getImage ("/path/to/imageFile");
MediaTracker tracker = new MediaTracker(new Frame());
tracker.addImage(im, 0);
tracker.waitForAll (); %>
Image size : <%= im.getWidth (null) %>, <%= im.getHeight (null) %>
---
Manu (moderator/modérateur)


Home pageFind It!ContactTop

© Copyrights 1997-2023 eTeks - All rights reserved

PJAPJA documentation