Exemple #1
0
 private String getExifData(ImagePlus imp) {
   FileInfo fi = imp.getOriginalFileInfo();
   if (fi == null) return null;
   String directory = fi.directory;
   String name = fi.fileName;
   if (directory == null) return null;
   if ((name == null || name.equals("")) && imp.getStack().isVirtual())
     name = imp.getStack().getSliceLabel(imp.getCurrentSlice());
   if (name == null || !(name.endsWith("jpg") || name.endsWith("JPG"))) return null;
   String path = directory + name;
   String metadata = null;
   try {
     Class c = IJ.getClassLoader().loadClass("Exif_Reader");
     if (c == null) return null;
     String methodName = "getMetadata";
     Class[] argClasses = new Class[1];
     argClasses[0] = methodName.getClass();
     Method m = c.getMethod("getMetadata", argClasses);
     Object[] args = new Object[1];
     args[0] = path;
     Object obj = m.invoke(null, args);
     metadata = obj != null ? obj.toString() : null;
   } catch (Exception e) {
     return null;
   }
   if (metadata != null && !metadata.startsWith("Error:")) return metadata;
   else return null;
 }
Exemple #2
0
  /** Install the plugins now */
  public void run(String arg) {
    if ("update".equals(arg)) {
      Menus.updateImageJMenus();
      ClassLoader loader = IJ.getClassLoader();
      if (loader != null && (loader instanceof FijiClassLoader)) return;
    }
    FijiClassLoader classLoader = new FijiClassLoader(true);
    try {
      classLoader.addPath(path);
    } catch (IOException e) {
    }

    try {
      // IJ.setClassLoader(classLoader);
      Class ij = Class.forName("ij.IJ");
      java.lang.reflect.Method method =
          ij.getDeclaredMethod("setClassLoader", new Class[] {ClassLoader.class});
      method.setAccessible(true);
      method.invoke(null, new Object[] {classLoader});
    } catch (Exception e) {
      e.printStackTrace();
    }

    installScripts();
    installPlugins(path, ".", menuPath);
    /* make sure "Update Menus" runs _this_ plugin */
    Menus.getCommands().put("Update Menus", "fiji.User_Plugins(\"update\")");
    Menus.getCommands().put("Refresh Menus", "fiji.User_Plugins(\"update\")");
    Menus.getCommands().put("Compile and Run...", "fiji.Compile_and_Run");
    if (IJ.getInstance() != null) {
      Menu help = Menus.getMenuBar().getHelpMenu();
      for (int i = help.getItemCount() - 1; i >= 0; i--) {
        MenuItem item = help.getItem(i);
        String name = item.getLabel();
        if (name.equals("Update Menus")) item.setLabel("Refresh Menus");
      }
    }

    // make sure "Edit>Options>Memory & Threads runs Fiji's plugin
    Menus.getCommands().put("Memory & Threads...", "fiji.Memory");

    SampleImageLoader.install();
    Main.installRecentCommands();
  }
Exemple #3
0
 /** Opens an image file using the Bio-Formats plugin. */
 public static ImagePlus openUsingBioFormats(String path) {
   String className = "loci.plugins.BF";
   String methodName = "openImagePlus";
   try {
     Class c = IJ.getClassLoader().loadClass(className);
     if (c == null) return null;
     Class[] argClasses = new Class[1];
     argClasses[0] = methodName.getClass();
     Method m = c.getMethod(methodName, argClasses);
     Object[] args = new Object[1];
     args[0] = path;
     Object obj = m.invoke(null, args);
     ImagePlus[] images = obj != null ? (ImagePlus[]) obj : null;
     if (images == null || images.length == 0) return null;
     ImagePlus imp = images[0];
     if (imp.getStackSize() == 3 && imp.getNChannels() == 3 && imp.getBitDepth() == 8)
       imp = imp.flatten();
     return imp;
   } catch (Exception e) {
   }
   return null;
 }