문제

I'm trying to add a JPEG comment to an image file using WPF. Trying the following code throws me an ArgumentOutOfRangeException. Setting other properties works without problems.

    using (Stream read = File.OpenRead(@"my.jpeg"))
    {
        JpegBitmapDecoder decoder = new JpegBitmapDecoder(read, BitmapCreateOptions.None, BitmapCacheOption.None);

        var meta = decoder.Frames[0].Metadata.Clone() as BitmapMetadata;
        meta.SetQuery("/app1/ifd/exif:{uint=40092}", "xxx"); // works
        meta.SetQuery("/com/TextEntry", "xxx"); // does not work
    }

To be clear: I have to set the /com/TextEntry field which is listed in MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/ee719904%28v=vs.85%29.aspx#_jpeg_metadata

The data is read by another application which only supports this tag, so it is not an option to use other "comment" fields.

Any ideas?

도움이 되었습니까?

해결책

The data type for /com/TextEntry is a bit tricky, it requires an LPSTR. Which is a raw 8-bit encoded string pointer. You can do this by passing a char[] for the argument. Fix:

   meta.SetQuery("/com/TextEntry", "xxx".ToCharArray());

Do note that text encoding might be an issue if you use non-ASCII characters, you'll get text encoded in the machine's default code page (Encoding.Default).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top