Converting script from IJM to Java/Javascript: setMetadata

Hi,
I am trying to convert some old Macros, but I have a hard time finding the Java/JS equivalence for the following:
“setMetadata(imp, “Info”, content)”.

Can you help?
Thanks.

Is this is what you are after?
https://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html#setFileInfo-ij.io.FileInfo-

Hello diyoyo -

Use the ImagePlus.setProperty() method with "Info" as the
value for its key argument.

Here are paired IJM and jython scripts that illustrate this. First
run:

// IJM macro
newImage ("metadata", "8-bit ramp", 256, 256, 1);
print ("getMetadata = " + getMetadata ("Info"));
setMetadata ("Info", "IJM info");
print ("getMetadata = " + getMetadata ("Info"));

Then, leaving the “metadata” image open, run:

# jython script
from ij import IJ
imp = IJ.getImage()
print 'getProperty ("Info") =', imp.getProperty ("Info")
imp.setProperty ('Info', 'py info')
print 'getProperty ("Info") =', imp.getProperty ("Info")

(My use of jython is irrelevant – you would use
ImagePlus.setProperty() analogously in javascript or
directly from java.)

Thanks, mm

1 Like