  public BufferedImage openImage(int no)
    throws FormatException, IOException
  {
    FormatTools.assertId(currentId, true, 1);
    if (no < 0 || no >= getImageCount()) {
      throw new FormatException("Invalid image number: " + no);
    }
    if (noImageJ) throw new FormatException(NO_IJ);
    try {
      Location file = new Location(currentId);
      r.setVar("dir", file.getParent() + System.getProperty("file.separator"));
      r.setVar("name", file.getName());
      synchronized (ImageJReader.class) {
        try {
          r.exec("state = Opener.getOpenUsingPlugins()");
          r.exec("Opener.setOpenUsingPlugins(false)");
        }
        catch (ReflectException exc) {
        }
        r.exec("image = opener.openImage(dir, name)");
        try {
          r.exec("Opener.setOpenUsingPlugins(state)");
        }
        catch (ReflectException exc) {
        }
      }
      r.exec("size = image.getStackSize()");
      Image img = (Image) r.exec("image.getImage()");
      BufferedImage b = ImageTools.makeBuffered(img);
      return b;
    }
    catch (ReflectException exc) {
      throw new FormatException(exc);
    }
  }

  public BufferedImage openImage(int no)
    throws FormatException, IOException
  {
    FormatTools.assertId(currentId, true, 1);
    if (no < 0 || no >= getImageCount()) {
      throw new FormatException("Invalid image number: " + no);
    }
    if (noImageJ) throw new FormatException(NO_IJ);
    try {
      Location file = new Location(currentId).getAbsoluteFile();
      r.setVar("dir", file.getParent() + System.getProperty("file.separator"));
      r.setVar("name", file.getName());
      synchronized (ImageJReader.class) {
        try {
          r.exec("state = Opener.getOpenUsingPlugins()");
          r.exec("Opener.setOpenUsingPlugins(false)");
        }
        catch (ReflectException exc) {
        }
        r.exec("image = opener.openImage(dir, name)");
        try {
          r.exec("Opener.setOpenUsingPlugins(state)");
        }
        catch (ReflectException exc) {
        }
      }
      if (r.getVar("image") == null) {
        throw new FormatException("ImageJ cannot read this image");
      }
      r.exec("size = image.getStackSize()");
      Image img = (Image) r.exec("image.getImage()");
      BufferedImage b = ImageTools.makeBuffered(img);
      return b;
    }
    catch (ReflectException exc) {
      throw new FormatException(exc);
    }
  }
