File size

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

File size

Dimitri Vanhecke-2
Hello,

I want to use the physical size (file size) of an image for a PlugIn in ImageJ/Java.
I used "FileInfo" to retrieve the path and I have been playing around with  

long length = file.length();

but had no success actually getting the size of this image.


public class Tool_ implements PlugInFilter {

            private ImagePlus imp;
        public int setup(String arg, ImagePlus imp) {
                this.imp=imp;
                return DOES_ALL;
        }
  public void run(ImageProcessor ip) {
             String geg = getImageInfo(imp, ip);
        }

        public String getImageInfo(ImagePlus imp, ImageProcessor ip) {
        String geg = "";
        FileInfo fi = imp.getOriginalFileInfo();

        ****
               GenericDialog fs = new GenericDialog("File Size");
            fs.addNumericField("Filesize: ", filesize,0);
            fs.addStringField("Filename: ", fi.directory + fi.fileName,0);
                    fs.showDialog();
        return geg;
        }
}


Any input welcome!

Dimitri Vanhecke
Institute of Anatomy
University of Bern
Reply | Threaded
Open this post in threaded view
|

Re: File size

Thomas Boudier
Hi Dimitri,

The simplest thing to do is to create a java File object :

File myfile = new File("..."); // string path to your file
and then myfile.length();

Hope this helps

Thomas


Dimitri Vanhecke a écrit :

> Hello,
>
> I want to use the physical size (file size) of an image for a PlugIn in
> ImageJ/Java.
> I used "FileInfo" to retrieve the path and I have been playing around with
> long length = file.length();
>
> but had no success actually getting the size of this image.
>
>
> public class Tool_ implements PlugInFilter {
>
>            private ImagePlus imp;
>     public int setup(String arg, ImagePlus imp) {
>         this.imp=imp;
>         return DOES_ALL;
>     }
>     public void run(ImageProcessor ip) {
>                  String geg = getImageInfo(imp, ip);
>     }  
>
>     public String getImageInfo(ImagePlus imp, ImageProcessor ip) {
>     String geg = "";
>     FileInfo fi = imp.getOriginalFileInfo();
>
>     ****
>               GenericDialog fs = new GenericDialog("File Size");
>         fs.addNumericField("Filesize: ", filesize,0);
>         fs.addStringField("Filename: ", fi.directory +
> fi.fileName,0);      
>                    fs.showDialog();
>     return geg;
>     }  
> }
>
>
> Any input welcome!
>
> Dimitri Vanhecke
> Institute of Anatomy
> University of Bern
>
>

--
   /**********************************************************/
      Thomas Boudier, MCU Université Pierre et Marie Curie,
      IFR 83. Bat B 7ème étage, porte 709, Jussieu.
      Tel : 01 44 27 20 11  Fax : 01 44 27 22 91
/*******************************************************/