Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LINQPad script
- // References: System.Xaml, WindowsBase, PresentationCore
- // Namespaces: System.Windows.Media.Imaging
- void Main()
- {
- string path = @"(image_path)";
- Uri imageUri = new Uri(path);
- var decoder = BitmapDecoder.Create(imageUri, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
- // Global metadata
- DumpMetadata(decoder.Metadata);
- // Metadata for each frame
- DumpAllMetadata(decoder.Frames);
- }
- void DumpAllMetadata(IEnumerable<BitmapFrame> frames)
- {
- int i = 0;
- foreach (var f in frames)
- {
- using (var writer = new StringWriter())
- {
- DumpMetadata((BitmapMetadata)f.Metadata, writer);
- writer.ToString().Dump("Frame " + i++);
- }
- }
- }
- void DumpMetadata(BitmapMetadata metadata)
- {
- DumpMetadata(metadata, 0, Console.Out);
- }
- void DumpMetadata(BitmapMetadata metadata, TextWriter writer)
- {
- DumpMetadata(metadata, 0, writer);
- }
- void DumpMetadata(BitmapMetadata metadata, int indentLevel)
- {
- DumpMetadata(metadata, indentLevel, Console.Out);
- }
- void DumpMetadata(BitmapMetadata metadata, int indentLevel, TextWriter writer)
- {
- if (metadata == null)
- {
- writer.WriteLine ("(No metadata)");
- return;
- }
- string indent = new string('\t', indentLevel);
- foreach (var propertyName in metadata)
- {
- object value = metadata.GetQuery(propertyName);
- BitmapMetadata complexProperty = value as BitmapMetadata;
- if (complexProperty != null)
- {
- writer.WriteLine("{0}{1} =", indent, propertyName);
- DumpMetadata(complexProperty, indentLevel + 1, writer);
- }
- else
- {
- Type type = null;
- if (value != null)
- type = value.GetType();
- writer.WriteLine("{0}{1} = {2} ({3})", indent, propertyName, value, type);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement