Задайте вопросЗадайте вопрос
 

ВопросHow to write XMP tags to JPEGs

  • 3 июля 2009 г. 18:58diver182 Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     С кодом
    Having retrieved a mutable BitmapMetadata object from an image I was able to read and write different scheme tags (e.g. exif).
    Also XMP tags worked fine. At least those at the root level.

    Trying to write xmp alt/seq/bag tags to the file failed with the following System.NotSupportedException (working with Vista):

    "No imaging component suitable to complete this operation was found." with an inner exception of "HRESULT: 0x88982F50".
     
    The following code caused the error:

    // this all happens in a using directive, wrapping the FileStream of the image
    
    BitmapMetadata meta = null;
    JPEGEncoder encoder = new JPEGEncoder();
    // ... using (FileStream imgStream = ... ) 
    
    meta = decoder.Frames[0]... ;
    
    // ensuring there is enough space for an insert
    meta.SetQuery("/xmp/PaddingSchema:Padding", SomeUIntValue);
    // setting an xmp "node" for "complex" tags
    meta.SetQuery("/ifd/xmp", new BitmapMetadata("xmp"));
    // setting an xmp "container" for entries 
    meta.SetQuery("/ifd/xmp/dc:title", new BitmapMetadata("xmpalt" );
    // writing the tag
    meta.SetQuery("/ifd/xmp/dc:title/x-default", "New Title"); 
    // adding metadata to encoder for writing
    encoder.Frames.Add(..., meta, ...)
    
    // ... closing using directive and disposing the resources of the stream
    
    
    // Writing the updated Metadata by using another Filestream of the image
    // ... using (Filestream imgStream = ...) 
    
    // EXCEPTION when attempting to write metadata to file
    try 
    {
    encoder.Save(imgStream);
    } 
    catch (Exception ex) 
    {
    // NotSupportedException
    }
    
    // ... closing using directive and disposing the resources of the stream
    
    Any suggestions greatly appreciated.

Все ответы