IPTC-Tags mit Imagero schreiben

Mit folgendem Java Code kann man mit Imagero (Version 398) ein IPTC-Feld (hier: Keyword) schreiben. Ist der Keywords-Eintrag im Bild noch nicht vorhanden, wird er erstellt, andernfalls wird “foo” der Liste hinzugefügt.

public class TestImagero {
    public static void main(String[] args) throws Exception {
        LicenseManager.install(new FranzGraf());
        String src = "a.JPG";
        IOParameterBlock iopb = new IOParameterBlock(src);
        IOParameterBlock iopbDst = new IOParameterBlock(src).setDestination(src);
        IPTCEntryCollection iec = MetadataUtils.getIPTC(iopb);
        iec.addEntry(IPTCEntryMeta.KEYWORDS, "foo".getBytes());
        MetadataUtils.insertIPTC(iec, iopbDst);
        iopb.close();
        iopbDst.close();
    }
}

Einen Eintrag namens “foo_2” entfernt man aus den Keywords folgendermaßen:

            IOParameterBlock iopb = new IOParameterBlock(src);
            IOParameterBlock iopbDst = new IOParameterBlock(src).setDestination(src);
            IPTCEntryCollection iec = MetadataUtils.getIPTC(iopb);
            IPTCEntry[] entries = iec.getEntries(IPTCEntryMeta.KEYWORDS);
            List removes = new ArrayList();
            for (IPTCEntry entry : entries) {
                if (new String(entry.getData()).equals("foo_2")) {
                    removes.add(entry);
                }
            }
            for (IPTCEntry rem : removes) {
                System.out.println(iec.removeEntry(rem));
            }
            MetadataUtils.insertIPTC(iec, iopbDst);
            iopb.close();
            iopbDst.close();