- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathBitmapMetadata.cpp
92 lines (74 loc) · 3.18 KB
/
BitmapMetadata.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//BitmapMetadata.cpp file
usingnamespaceSystem;
usingnamespaceSystem::IO;
usingnamespaceSystem::Windows;
usingnamespaceSystem::Windows::Controls;
usingnamespaceSystem::Windows::Media;
usingnamespaceSystem::Windows::Media::Imaging;
usingnamespaceSystem::Threading;
usingnamespaceSystem::Security;
namespaceSDKSample {
public ref classapp : Application {
private: Window^ mainWindow;
protected:virtualvoidOnStartup (StartupEventArgs^ e) override
{
Application::OnStartup(e);
CreateAndShowMainWindow();
};
private:voidCreateAndShowMainWindow ()
{
// Create the application's main window
mainWindow = gcnew Window();
mainWindow->Title = "Image Metadata";
// <SnippetSetQuery>
Stream^ pngStream = gcnew FileStream("smiley.png", FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite);
PngBitmapDecoder^ pngDecoder = gcnew PngBitmapDecoder(pngStream, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapFrame^ pngFrame = pngDecoder->Frames[0];
InPlaceBitmapMetadataWriter^ pngInplace = pngFrame->CreateInPlaceBitmapMetadataWriter();
if (pngInplace->TrySave())
{
pngInplace->SetQuery("/Text/Description", "Have a nice day.");
}
pngStream->Close();
// </SnippetSetQuery>
// Draw the Image
Image^ myImage = gcnew Image();
myImage->Source = gcnew BitmapImage(gcnew System::Uri("smiley.png", UriKind::Relative));
myImage->Stretch = Stretch::None;
myImage->Margin = System::Windows::Thickness(20);
// <SnippetGetQuery>
// Add the metadata of the bitmap image to the text block.
TextBlock^ myTextBlock = gcnew TextBlock();
myTextBlock->Text = "The Description metadata of this image is: " + pngInplace->GetQuery("/Text/Description")->ToString();
// </SnippetGetQuery>
// Define a StackPanel to host Controls
StackPanel^ myStackPanel = gcnew StackPanel();
myStackPanel->Orientation = Orientation::Vertical;
myStackPanel->Height = 200;
myStackPanel->VerticalAlignment = VerticalAlignment::Top;
myStackPanel->HorizontalAlignment = HorizontalAlignment::Center;
// Add the Image and TextBlock to the parent Grid
myStackPanel->Children->Add(myImage);
myStackPanel->Children->Add(myTextBlock);
// Add the StackPanel as the Content of the Parent Window Object
mainWindow->Content = myStackPanel;
mainWindow->Show();
};
};
// Define a static entry class
private ref classEntryClass {
public:
[System::STAThread()]
staticvoidMain ()
{
SDKSample::app^ app = gcnew SDKSample::app();
app->Run();
};
};
}
//Entry Point:
[System::STAThreadAttribute()]
voidmain ()
{
returnSDKSample::EntryClass::Main();
}