1

I'm currently using the ij.jar in a Java application and using ImageJ to save some processed images to the disk. However, if I try to save an image to a file that already exists, the save fails silently. The original file remains untouched and ImageJ does not throw an error.

Here is a sample piece of code:

IJ.saveAs(image, filename);

Is there a way to have saveAs automatically overwrite if a file with the same name already exists?

1 Answer 1

1

I think you'll be best off using the FileSaver class (ij.io.FileSaver) instead of the generic saveAs method. For example, if your ImagePlus is image, then you can save it as a TIFF stack with:

new FileSaver(image).saveAsTiffStack(path);

If you need another format, have a look at the documentation, and you'll see that there are similar methods for other formats.

2
  • @Mark_Longair is the filename included in the path?
    – Ivan
    Commented Oct 11, 2012 at 22:08
  • @Ivan: yes, the path should be a String including the filename Commented Oct 12, 2012 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.