Getting Height and Width of Image in Java without an ImageObserver -


i trying height , width of images (via url) in java without imageobserver. current code is:

public static void main(string[] args) throws ioexception {     // todo auto-generated method stub      file xmlimages = new file("c:\\images.xml");     bufferedreader br = new bufferedreader(new filereader(xmlimages));     file output = new file("c:\\images.csv");     bufferedwriter bw = new bufferedwriter(new filewriter(output));     stringbuffer sb = new stringbuffer();     string line = null;     string newline = system.getproperty("line.separator");     while((line = br.readline()) != null){         if(line.contains("http")){             url url = new url(line.)             image img = toolkit.getdefaulttoolkit().getimage(url);             sb.append(line + ","+ img.getheight(null) + "," + img.getwidth(null) + newline);                     }      }      br.close();     bw.write(sb.tostring());     bw.close(); } 

when go debug mode able see image loaded , can see height , width of image, can't seem return them. getheight() , getwidth() methods require image observer, don't have. thank in advance.

you can use imageicon handle loading of image you.

change

image img = toolkit.getdefaulttoolkit().getimage(url); sb.append(line + ","+ img.getheight(null) + "," + img.getwidth(null) + newline); 

to

imageicon img = new imageicon(url); sb.append(line + ","+ img.geticonheight(null) + "," + img.geticonwidth(null) + newline); 

the main change use imageicon, , geticonwidth, geticonheight methods.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -