Skip to main content

Writing IPTC metadata with imagero

7 replies [Last post]
deadpassive
Offline
Joined: 2009-02-05
Points: 0

Hi, I know this isn't technically a JAI thing but I was wondering if you guys could help.

Basically, I'm writing a program to randomly loop through my images and allow me to tag them using IPTC keywords (Google Picasa seems to use them...). I'm using imagero to read the IPTC metadata and I'm trying to add a test tag and save it back to the file. However, I get a NullPointerException. My code and the full stack trace are below. Can anybody see what I'm doing wrong? Thanks!

File source = imageList.get(currentIndex);
System.out.println("Writing metadata to: " + source);
IOParameterBlock iopb = new IOParameterBlock(source);
iopb.setDestination(source);
currentKeywords = IPTC.getIPTC(iopb);
Enumeration e = currentKeywords.entries();
while (e.hasMoreElements()) {
IPTCEntry entry = (IPTCEntry)e.nextElement();
System.out.println(entry);
}
currentKeywords.addEntry(IPTCEntryMeta.KEYWORDS, "test".getBytes());
IPTC.insertIPTC(currentKeywords, iopb);

Exception in thread "main" java.lang.NullPointerException
at com.imagero.uio.bio.BufferedRandomAccessIO.length(BufferedRandomAccessIO.java:101)
at com.imagero.reader.v.a(v.java:29)
at com.imagero.reader.ImageProcOptions.(ImageProcOptions.java:136)
at com.imagero.reader.iptc.IPTC.insertIPTC(IPTC.java:14)
at uk.ac.glam.jbritton.tagger.ImageTagger.(ImageTagger.java:119)
at uk.ac.glam.jbritton.tagger.ImageTagger.main(ImageTagger.java:150)

NOTE: ImageTagger:119 refers to the last line in the above code.

Thanks again!

Message was edited by: deadpassive

Message was edited by: deadpassive

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
imagero
Offline
Joined: 2003-11-18
Points: 0

BTW if you trying to register in forum with crazy username (like dead_passive) I thinking that it is just a next spammer and don't activate account...

deadpassive
Offline
Joined: 2009-02-05
Points: 0

Really? That's the username I use for everything? :-(

I'll try again with another one though and thanks for your help, I'll give it a try when I get the chance!

Thanks

imagero
Offline
Joined: 2003-11-18
Points: 0

It is better if you ask in imagero forum.

You getting NPE due to fact that your stream was closed.

IPTC.getIPTC(iopb) closes stream just after reading IPTC.

You can
a) use another IOParameterBlock
IOParameterBlock src = new IOParameterBlock(source);
IOParameterBlock dst = new IOParameterBlock(source).setDestination(source);

currentKeywords = IPTC.getIPTC(src);

currentKeywords.addEntry(IPTCEntryMeta.KEYWORDS, "test".getBytes());
IPTC.insertIPTC(currentKeywords, dest);

or

b) use this code:

IOParameterBlock iopb = new IOParameterBlock(source).setDestination(source);
ImageProcOptions options = new ImageProcOptions(iopb);

IPTCEntryCollection currentKeywords = IPTC.getIPTC(options);

IPTC.insertIPTC((JpegFile) options.imageFile, currentKeywords, iopb);

emeratius
Offline
Joined: 2009-01-16
Points: 0

I keep getting NPE:
Exception in thread "main" java.lang.NullPointerException
at com.imagero.reader.ImageFile.a(ImageFile.java:26)
at com.imagero.reader.ImageFile.(ImageFile.java:5)
at com.imagero.reader.jpeg.JpegFile.(JpegFile.java:37)
at com.imagero.reader.iptc.IPTC.a(IPTC.java:26)
at com.imagero.reader.iptc.IPTC.getIPTC(IPTC.java:35)

imagero
Offline
Joined: 2003-11-18
Points: 0

Here is the wrong place for discussions about imagero.
Why don't you ask me per email?

robert engels

THere is no stack trace...

On Feb 5, 2009, at 3:23 PM, jai-imageio@javadesktop.org wrote:

> Hi, I know this isn't technically a JAI thing but I was wondering
> if you guys could help.
>
> Basically, I'm writing a program to randomly loop through my images
> and allow me to tag them using IPTC keywords (Google Picasa seems
> to use them...). I'm using imagero to read the IPTC metadata and
> I'm trying to add a test tag and save it back to the file.
> However, I get a NullPointerException. My code and the full stack
> trace are below. Can anybody see what I'm doing wrong? Thanks!
>
> File source = imageList.get(currentIndex);
> System.out.println("Writing metadata to: " + source);
> IOParameterBlock iopb = new IOParameterBlock(source);
> iopb.setDestination(source);
> currentKeywords = IPTC.getIPTC(iopb);
> Enumeration e = currentKeywords.entries();
> while (e.hasMoreElements()) {
> IPTCEntry entry = (IPTCEntry)e.nextElement();
> System.out.println(entry);
> }
> currentKeywords.addEntry(IPTCEntryMeta.KEYWORDS, "test".getBytes());
> IPTC.insertIPTC(currentKeywords, iopb);
>
> Thanks again!
> [Message sent by forum member 'deadpassive' (deadpassive)]
>
> http://forums.java.net/jive/thread.jspa?messageID=330403
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-
> imageio.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

deadpassive
Offline
Joined: 2009-02-05
Points: 0

Cheers, I've edited the original post now.