how to get image size
public int[] getWidth_height(String imgPath)
{
int a[]=new int[2];
a[0]=10;
a[1]=10;
try
{
BufferedImage mImage = ImageIO.read(new File(imgPath));
a[0]= mImage.getWidth();
a[1]=mImage.getHeight();
return a;
}catch (IOException ex)
{
ex.getMessage();
}
return a;
}
********************************************************************
i don't know why i just can run this method in main(). when i call this
method on JSP and read the path (\\\\192.168.0.1\\XXX\\XXX.jpg), it
returns a exception about 'can't read file' (a[0] and a[1] return 10). how can i solve it?
many thanks,
[715 byte] By [
biosa] at [2007-11-26 18:02:14]

# 1
Your code works when I try to read the width and height of a file on the local disk
package test21;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.File;
public class ImageTest {
public static void main(String[] args) {
//This works
int[] widthHeight = getWidth_height("C:\\someimage.jpg");
//This doesn't work
int[] widthHeight = getWidth_height("http:\\\\www.google.com\\intl\\en_ALL\\images\\logo.gif");
System.out.println(" Image Width : " + widthHeight[0] + " image Height: " + widthHeight[1]);
}
public static int[] getWidth_height(String imgPath) {
int a[] = new int[2];
a[0] = 10;
a[1] = 10;
try {
BufferedImage mImage = ImageIO.read(new File(imgPath));
a[0] = mImage.getWidth();
a[1] = mImage.getHeight();
return a;
} catch (IOException ex) {
ex.printStackTrace();
}
return a;
}
}
The code that tries to get height and width of an image on another website/ ip address throws this error:
javax.imageio.IIOException: Can't read input file!
Image Width : 10 image Height: 10
at javax.imageio.ImageIO.read(ImageIO.java:1279)
at test21.ImageTest.getWidth_height(ImageTest.java:22)
at test21.ImageTest.main(ImageTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Are you sure you have access to the IP address you are querying. By this I mean, is there a Firewall , a blocked port or something that is preventing access to that IP address or the image file?
Message was edited by:
appy77