Permalink
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (66 sloc) 2.71 KB
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Threading;
namespace SDKSample
{
public class app : Application
{
Window mainWindow;
protected override void OnStartup (StartupEventArgs e)
{
base.OnStartup (e);
CreateAndShowMainWindow ();
}
private void CreateAndShowMainWindow ()
{
// Create the application's main window
mainWindow = new Window ();
mainWindow.Title = "Image Metadata";
// <SnippetSetQuery>
Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame pngFrame = pngDecoder.Frames[0];
InPlaceBitmapMetadataWriter pngInplace = pngFrame.CreateInPlaceBitmapMetadataWriter();
if (pngInplace.TrySave() == true)
{ pngInplace.SetQuery("/Text/Description", "Have a nice day."); }
pngStream.Close();
// </SnippetSetQuery>
// Draw the Image
Image myImage = new Image();
myImage.Source = new BitmapImage(new Uri("smiley.png", UriKind.Relative));
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(20);
// <SnippetGetQuery>
// Add the metadata of the bitmap image to the text block.
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "The Description metadata of this image is: " + pngInplace.GetQuery("/Text/Description").ToString();
// </SnippetGetQuery>
// Define a StackPanel to host Controls
StackPanel myStackPanel = new 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
internal static class EntryClass
{
[System.STAThread()]
private static void Main ()
{
app app = new app ();
app.Run ();
}
}
}