-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (58 loc) · 2.48 KB
/
Copy pathProgram.cs
File metadata and controls
65 lines (58 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.IO;
using System.Text;
using ImageGear.Core;
using ImageGear.Formats;
namespace MetadataGeneralAPI
{
class Program
{
private static void RecursivelyWriteMetadata(ImGearMetadataTree tree, StringBuilder outputStringBuilder)
{
foreach (ImGearMetadataNode child in tree.Children)
{
// If the child is a leaf, then parse its data.
if (child is ImGearMetadataLeaf leaf)
{
// If the data is an array, record its elements as a comma-separated list.
if (leaf.Data is Array items)
{
outputStringBuilder.AppendFormat("{0}: [", leaf.Name);
foreach (object item in items)
{
outputStringBuilder.AppendFormat("{0},", item);
}
outputStringBuilder.Append("]\r\n");
}
// Otherwise simply record the data as a string.
else
{
outputStringBuilder.AppendFormat("{0}: {1}\r\n", leaf.Name, leaf.Data);
}
}
// If the child is itself a tree, then recursively call this function.
else if (child is ImGearMetadataTree subtree)
{
outputStringBuilder.AppendFormat("begin {0}\r\n", subtree.Name);
RecursivelyWriteMetadata(subtree, outputStringBuilder);
outputStringBuilder.AppendFormat("end {0}\r\n", subtree.Name);
}
}
}
static void Main()
{
// Initialize common formats.
ImGearCommonFormats.Initialize();
// Load image page.
ImGearPage imGearPage;
using (FileStream stream = new FileStream(@"../../../../../../Sample Input/single-page.png", FileMode.Open, FileAccess.Read, FileShare.Read))
imGearPage = ImGearFileFormats.LoadPage(stream, 0);
// Collect image metadata into a StringBuilder.
StringBuilder outputStringBuilder = new StringBuilder();
ImGearMetadataTree metadata = (ImGearMetadataTree)imGearPage.Metadata.Child;
RecursivelyWriteMetadata(metadata, outputStringBuilder);
// Output the resulting string.
Console.Write(outputStringBuilder.ToString());
}
}
}