ImageMetadata change property is corrupted
Asked Answered
H

1

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

Hullo answered 17/6, 2019 at 9:22 Comment(0)
B
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)
Beardless answered 24/6, 2019 at 19:9 Comment(3)
Thanks for the explanation, but the image already contains an iptc data. So I will be overwriting it. If I try to GetQuery("/ifd/iptc"), I get the correct values returned. So If I do the above, I will be overwriting maybe other iptc properties, and loosing info.Hullo
@Hullo - you have to create the metadata the same way as WIC/WPF reads it. It means you have to read the whole tree (containing intermediary BitmapMetadata objects), and rewrite it after updating or adding new value, keeping the intermediary objects tree structure identical. There's no way around this if you want to use what Windows provides.Beardless
Could you modify my sample application to show what you mean? What you do above is overwriting the whole IPTC metadata in the image. But I need to preserve it. The second image in my test project gives corrupted error on save.Hullo

© 2022 - 2024 — McMap. All rights reserved.