How to get image properties (HTML)
[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]
This shows 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
- Building your first Windows Windows Runtime app using JavaScript
- Windows.Storage.FileProperties.ImageProperties
- Windows Properties
Prerequisites
- We assume that you can create a basic Windows Runtime app using JavaScript. For more info, see Building your first Windows Windows Runtime app using JavaScript.
- You have created a StorageFile object from the image. How to decode an image walks you through that process.
Instructions
Step 1: Get a file object
Write the beginning of a function that receives a StorageFile object and declare variables in which to store the properties you retrieve.
function GetImageProperties(file) {
var title;
var orientation;
var aperture;
Declare the variables here to keep them in scope.
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.
file.properties.getImagePropertiesAsync().then(function (imageProperties) {
When you have the ImageProperties object, you can immediately get some common properties, like title and rating.
title = imageProperties.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 imageProperties.retrievePropertiesAsync.
return imageProperties.retrievePropertiesAsync(["System.Photo.Orientation", “System.Photo.Aperture”]);
}).done(function (retrievedProperties) {
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.
orientation = retrievedProperties.lookup("System.Photo.Orientation");
aperture = retrievedProperties.lookup("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 imaging metadata.