ImageMetadata change property is corrupted

7

I have a working application to change some of the metadata of my scanned images. This was working good, until we added a pre-process to automatically crop the borders of the images with GIMP console.

We change multiple fields in the EXIF data, and this still works correct. But if I want to change any IPTC field, I get the error "Property is corrupted."

For the non cropped images, I can change EXIF and IPTC without any problem. For the cropped images, I can change EXIF without any problem. If I change anything in IPTC info, I get an exception.

Am I doing something wrong? Or is there maybe an other solution on how to change the EXIF/IPTC data of the images?

As found in other posts, I extract the BitmapMetadata from the image. And I clone it, to be editable. After that I add padding to be able to add extra information.

As far as I can see, there looks nothing wrong with the metadata. And in other tools like IrfanView or EXIFTool, I can change the IPTC Headline correct.

I have created a test project where the issue is shown. Included with an example image before and after crop.

If isJpg Then
    oMetaData.SetQuery("/app13/{ushort=0}/{ulonglong=61857348781060}/iptc/{str=Headline}", "TEST_HEADLINE")
Else
    oMetaData.SetQuery("/ifd/{ushort=33723}/{str=Headline}", "TEST_HEADLINE")
End If

System.ArgumentException: Property is corrupted. ---> System.Runtime.InteropServices.COMException: The bitmap property size is invalid. (Exception from HRESULT: 0x88982F42)

Example project

.net
exif
iptc
asked on Stack Overflow Jun 17, 2019 by Stinus

1 Answer

1

Meta data is a hierarchy, so you cannot write everything using only paths, you'll have to use intermediate BitmapMetadata objects.

The official documentation for all this is located here: Native Image Format Metadata Queries which is part of WIC or Windows Imaging Component documentation, the underlying Windows imaging technology that WPF uses.

The doc says this for TIFFs:

/ifd/iptc or /ifd/{ushort=33723} / IPTC / VT_UNKNOWN - A query reader/writer

The obscure VT_UNKNOWN (for "Variant Type IUnknown") in fact means iptc is an object that can read and write meta data (aka: a BitmapMetadata in WPF parlance), the start of a meta data sub tree.

So what you must do is something like this:

Dim iptc As BitmapMetadata = New BitmapMetadata("iptc")
iptc.SetQuery("/{str=Headline}", "TEST_HEADLINE")
oMetaData.SetQuery("/ifd/iptc", iptc)
answered on Stack Overflow Jun 24, 2019 by Simon Mourier

User contributions licensed under CC BY-SA 3.0