locked
writing metadata RRS feed

  • Question

  • Hello guys.

    I'm curious about the quickstart which talks about writing metadata to an image that is shown here: http://msdn.microsoft.com/en-us/library/windows/apps/hh465095.aspx

    I'm under the impression that it says that we need a decoder to write metadata. However, I can't find the savePropertiesAsync method which should be exposed by the encoder...the only way I've found to save metadata was to retrieve the properties associated with a StorageFile object, get the metadata from that StorageItemContentProperties object by using the getImagePropertiesAsync method, change them, and then persist them again by calling the StorageFile's saveProperties Async method.

    So, I'm assuming that this quick start is completely out dated, right?

    btw, am I also right to assume that the sample which shows how to get metadata wouldn't really require me to use a decoder?

    thanks


    Luis Abreu

    Tuesday, May 15, 2012 12:05 PM

Answers

  • Sorry Luis,

    I lost track of this one.  Yes the sample is outdated and the function does not exist.  I think you could set the properties and then once done call FlushAsync.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, June 20, 2012 1:00 PM
    Moderator

All replies

  • As the quickstart notes: http://msdn.microsoft.com/en-us/library/windows/apps/hh465095.aspx

    There are two classes of properties.  You do not need an encoder of the image supports natively the particular property:

    Note  You can set the properties height, width, title, keywords, rating, and  date-taken using the Windows.Storage.FileProperties class.  If you don't need any other properties, you can get FileProperties object from a Windows.StorageFile without opening a stream.

    If you need other properties you need to use the stream technique.

    Also you can see this in action in this sample: http://code.msdn.microsoft.com/windowsapps/Simple-Imaging-Sample-a2dec2b0

    -Jeff


    Jeff Sanders (MSFT)


    Tuesday, May 15, 2012 2:01 PM
    Moderator
  • Hello again Jeff.

    Yes, I understood that part. But what I'm asking is something different. If you look at that sample, you'll notice that you can get the metadata values from the decoder or by going through the storagefile  object.

    For instance, here's some code that shows going through the decoder:

    ficheiro.openAsync(modoAcesso)
                .then(function (stream) {
                    streamRef = stream;
                    return Windows.Graphics.Imaging.BitmapDecoder.createAsync(stream);                
                })
            .then(function (decoder) {
                return decoder.bitmapProperties.getPropertiesAsync([
                    "System.Photo.Orientation",
                    "System.Photo.CameraModel",
                    "System.Photo.CameraManufacturer"]);
            })
            .then(function (props) {
                var orientacao = props.lookup("System.Photo.Orientation");
                var modelo = props.lookup("System.Photo.CameraModel");
                var fabricante =  props.lookup("System.Photo.CameraManufacturer");
                document.getElementById("info").innerHTML += 
                    "Orientação: " + orientacao.value + "<br>" +
                    "Modelo: " + modelo.value + "<br>";
                document.getElementById("fabricante").value = fabricante.value;
                streamRef.close();
            });

    And here's some code which goes through the file.properties path:

    function alterarFabricante() {
            if (!ficheiro) return;
            ficheiro.properties.getImagePropertiesAsync()
                .then(function (props) {
                    return props.retrievePropertiesAsync(["System.Photo.CameraManufacturer"]);
                })
            .then(function (metadataProps) {
                metadataProps["System.Photo.CameraManufacturer"] = document.getElementById("fabricante").value;
                return ficheiro.properties.savePropertiesAsync(metadataProps);
            })        
            .done(null,
            function (err) {
                info.innerHTML = "Ocorreu um erro ao gravar o frabricante: " + err;
            });
        }

    Yes, I know, the results returned are different (the decoder returns some sort of collection on an object - forgot its name - while the other returns strings), but still, you do get the values back.

    Now, i'm assuming that you missed the 1st question, regarding the savePropertiesAsync method. the docs say it's exposed by the decoder, but I can't find it. The sample you mention seem to confirm my suspicions....


    Luis Abreu

    Tuesday, May 15, 2012 8:56 PM
  • Anyone?

    Luis Abreu

    Wednesday, June 20, 2012 12:52 PM
  • Sorry Luis,

    I lost track of this one.  Yes the sample is outdated and the function does not exist.  I think you could set the properties and then once done call FlushAsync.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, June 20, 2012 1:00 PM
    Moderator
  • Thanks Jeff.

    Luis Abreu

    Wednesday, June 20, 2012 5:59 PM