Partager via


How to get image properties (XAML)

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

We show you how to use an ImageProperties object to retrieve properties from an image file.

If you don't have a BitmapDecoder object, or you only need commonly used imaging properties, then we recommend you use the ImageProperties class. ImageProperties gives you basic data such as title and date taken. It also provides access to the Windows property system, which contains many commonly used properties. For more info, the complete Windows property namespace can be found at: Windows Properties.

Note  Only some properties are supported by the image formats and codecs. For more info, see Photo Metadata Policies

 

What you need to know

Technologies

Prerequisites

Instructions

Step 1: Get a file object

Write the beginning of a function that receives a StorageFile object containing an image.

async void GetImageProperties(Windows.Storage.StorageFile file)
{

Step 2: Retrieve a basic property

StorageFile has a member Properties that provides access to content-related properties on the file. You can get imaging properties using Properties.GetImagePropertiesAsync.

    var imageProps = await file.Properties.GetImagePropertiesAsync();

When you have the ImageProperties object, you can immediately get some common properties, like title and rating.

    var title = imageProps.Title;

Note  If the image doesn't contain a particular property, or if the image format doesn't support that property, it returns null. You must check that each property exists before you retrieve it.

 

Step 3: Retrieve a Windows property

You can also asynchronously request a supported Windows property by passing a list of property key names to RetrievePropertiesAsync.

    var requests = new System.Collections.Generic.List<string>();
    requests.Add("System.Photo.Orientation");
    requests.Add("System.Photo.Aperture");

    var retrievedProps = await imageProps.RetrievePropertiesAsync(requests);

The retrievedProperties object is a collection of key-value pairs where each key is the Windows property name you requested, and the value is the corresponding data. When you call the lookup function, it is synchronous. The RetrievePropertiesAsync function handles the processing.

    ushort orientation;
    if (retrievedProps.ContainsKey("System.Photo.Orientation"))
    {
        orientation = (ushort)retrievedProps["System.Photo.Orientation"];
    }

    double aperture;
    if (retrievedProps.ContainsKey("System.Photo.Aperture"))
    {
        aperture = (double)retrievedProps["System.Photo.Aperture"];
    }

Note  If the image doesn't contain a particular property, or if the image format doesn't support that property, it returns null. You must check that each property exists before you retrieve it.

 

Remarks

You can use BitmapPropertiesView to get Windows properties, like ImageProperties. But it provides lower level access to the native metadata structures in the file using the WIC metadata query language. For more info, see How to read image metadata.

Simple imaging sample

Windows.Storage.FileProperties.ImageProperties

How to decode an image

How to read image metadata

Windows Properties

Supported Windows properties