http://imagej.273.s1.nabble.com/Extensible-Persistent-Properties-for-ImageJ-Images-tp5023228p5023229.html
> I’m using ImageJ 1.52 as a Java library. for my own Java application.
>
> I create images that are to be saved and restored. I want to attach extra information to an ImagePlus that will be persisted and restored using the standard ImageJ open and save operations.
>
> I’ve discovered that only some specific ImagePlus properties are persisted with the default ImageJ file operations (such as the “Info” property)
>
> The “Info”, appears itself to be a string formatted in a manor that is itself a list of properties. Can I safely append more (sub) properties to this “Info” property and expect them to be safel honoured by future versions of ImageJ 1.xx?
> The code below does what I want, but is it future safe?
> Also why are not all ImagePlus properties persisted?
> Is there some other mechanism for save augmenting an Image in ImageJ with extensible metadata that I am missing?
> I intend to add my extra properties with a reverse domain name notation key to avoid accidental clashes.
>
> /**
> * Adds a key-value pair to this ImagePlus's Info properties. The key is
> * removed from the properties table if value is null.
> *
> * @param imagePlus
> * @param key
> * @param value
> * @throws IOException
> * @see #getInfoProperties
> */
> void setInfoProperty(ImagePlus imagePlus, String key, String value) throws IOException {
> Properties infoProperties = getInfoProperties(imagePlus);
> if (value == null) {
> infoProperties.remove(key);
> } else {
> infoProperties.setProperty(key, value);
> }
> StringWriter sw = new StringWriter();
> infoProperties.store(sw, null);
> imagePlus.setProperty("Info", sw.toString());
> }
>
> /**
> * Get a property from an ImagePlus's Info properties.
> *
> * @param imagePlus
> * @param key
> * @return the
> * @see #getInfoProperties
> */
> String getInfoProperty(ImagePlus imagePlus, String key) throws IOException {
> return getInfoProperties(imagePlus).getProperty(key);
> }
>
> /**
> * Get the specified ImagePlus's Info properties. The "Info" properties are
> * a list of properties nested within the ImagePlus's property indexed with
> * the key value "Info". ImagePlus's "Info" property is saved and restored
> * by the default ImagePlus save and open operations.
> *
> * @param imagePlus
> * @param key
> * @return the
> */
> Properties getInfoProperties(ImagePlus imagePlus) throws IOException {
> Properties infoProps = new Properties();
> infoProps.load(new StringReader((String) imagePlus.getProperty("Info")));
> return infoProps;
> }
>
> Michael Ellis (Managing Director)
> Digital Scientific UK Ltd.
>
http://www.dsuk.biz <
http://www.dsuk.biz/>
>
[hidden email]
> tel: +44(0)1223 911215
>
> The Commercial Centre
> 6 Green End
> Cambridge
> CB23 7DY
>
> === END OF EMAIL ===
>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>