1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Net; 5 using System.Windows; 6 using System.Windows.Controls; 7 using System.Windows.Navigation; 8 using Microsoft.Phone.Controls; 9 using Microsoft.Phone.Shell; 10 using OpenCVXaml.Resources; 11 using System.Windows.Media.Imaging; 12 using OpenCVComponent; 13 14 namespace OpenCVXaml 15 { 16 public partial class MainPage : PhoneApplicationPage 17 { 18 private OpenCVLib m_opencv = new OpenCVLib(); 19 20 // Constructor MainPage()21 public MainPage() 22 { 23 InitializeComponent(); 24 25 // Sample code to localize the ApplicationBar 26 //BuildLocalizedApplicationBar(); 27 } 28 Button_Click(object sender, RoutedEventArgs e)29 private async void Button_Click(object sender, RoutedEventArgs e) 30 { 31 if (Preview.Source != null) 32 { 33 ProcessButton.IsEnabled = false; 34 35 // Get WriteableBitmap. ImageToModify is defined in MainPage.xaml 36 WriteableBitmap bitmap = new WriteableBitmap(Preview.Source as BitmapSource); 37 38 // call OpenCVLib to convert pixels to grayscale. This is an asynchronous call. 39 var pixels = await m_opencv.ProcessAsync(bitmap.Pixels, bitmap.PixelWidth, bitmap.PixelHeight); 40 41 // copy the pixels into the WriteableBitmap 42 for (int x = 0; x < bitmap.Pixels.Length; x++) 43 { 44 bitmap.Pixels[x] = pixels[x]; 45 } 46 47 // Set Image object, defined in XAML, to the modified bitmap. 48 Preview.Source = bitmap; 49 50 ProcessButton.IsEnabled = true; 51 } 52 } 53 54 // Sample code for building a localized ApplicationBar 55 //private void BuildLocalizedApplicationBar() 56 //{ 57 // // Set the page's ApplicationBar to a new instance of ApplicationBar. 58 // ApplicationBar = new ApplicationBar(); 59 60 // // Create a new button and set the text value to the localized string from AppResources. 61 // ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative)); 62 // appBarButton.Text = AppResources.AppBarButtonText; 63 // ApplicationBar.Buttons.Add(appBarButton); 64 65 // // Create a new menu item with the localized string from AppResources. 66 // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText); 67 // ApplicationBar.MenuItems.Add(appBarMenuItem); 68 //} 69 } 70 }