System metadata
System metadata is metadata collected during the import of the media file. These metadata belongs to the System MetadataDefinitionType.
ImageWidth and ImageHeight
If you need to retrieve the original media pixel size, this can be done using the ImageWidth and ImageHeight system metadata
Example
Here we get the ImageWidth and ImageHeight metadata using the direct apporach using LINQ.
var client = ClientFactory.GetSdkClient();
var media = client.Query<MediaItem>()
.Include(m => m.Metadata.Where(i => i.DefinitionType == MetadataDefinitionTypes.System && i.Name==SystemMetadata.Width))
.Include(m => m.Metadata.Where(i => i.DefinitionType == MetadataDefinitionTypes.System && i.Name == SystemMetadata.Height))
.ToList();
foreach (var mediaItem in media) {
var w = mediaItem.Metadata.FirstOrDefault(m => m.Name == SystemMetadata.Width);
var h = mediaItem.Metadata.FirstOrDefault(m => m.Name == SystemMetadata.Height);
Console.WriteLine(@"Id:{0},Width:{1},Height:{2}",mediaItem.Id,(w==null?"null":w.Value),(h==null?"null":h.Value));
}
You can also get the metadata using the declarative method using a derived class.
public class MyMedia : MediaItem {
[Metadata(SystemMetadata.Width,Type= MetadataDefinitionTypes.System)]
public int? Width { get; set; }
[Metadata(SystemMetadata.Height, Type = MetadataDefinitionTypes.System)]
public int? Height { get; set; }
}
The code to retrieve the media is then more simple.
var media2 = client.Query<MyMedia>().ToList();
foreach (var myMedia in media2) {
Console.WriteLine(@"Id:{0},Width:{1},Height:{2}", myMedia.Id, myMedia.Width, myMedia.Height);
}