private async void Button_Click(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(fileStream); OpenedImage.Source = bitmapImage; } NoPicButton.Visibility = Visibility.Collapsed; var schnitzelDetector = new SchnitzelDetector(); //TODO: Add secret key try { ResultTextBox.Text = String.Empty; ResultTextBox.Visibility = Visibility.Collapsed; IsLoadingGrid.Visibility = Visibility.Visible; var result = await schnitzelDetector.IsSchnitzel(file.Path, file.Name); if (result) { ResultTextBox.Text = "It's a schnitzel!!"; } else { ResultTextBox.Text = "Nope, it's not a schnitzel"; } } catch (Exception exception) { } finally { ResultTextBox.Visibility = Visibility.Visible; IsLoadingGrid.Visibility = Visibility.Collapsed; } //if (file != null) //{ // // Application now has read/write access to the picked file // this.textBlock.Text = "Picked photo: " + file.Name; //} //else //{ // this.textBlock.Text = "Operation cancelled."; //} }
partial void UIButton198_TouchUpInside(UIButton sender) { // Create and define UIImagePickerController var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary, MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary) }; // Set event handlers imagePicker.FinishedPickingMedia += async(s, e) => { imagePicker.DismissModalViewController(true); SelectImgLabel.Hidden = true; var sdetector = new SchnitzelDetector(); //TODO: add secret key var imgUrl = e.ImageUrl; MainImgView.ContentMode = UIViewContentMode.ScaleAspectFit; MainImgView.Image = e.OriginalImage; try { LoadingLabel.Hidden = false; LoadingIndicator.Hidden = false; IsSchnitzelLabel.Text = String.Empty; RedXImg.Hidden = true; GreenCImg.Hidden = true; var res = await sdetector.IsSchnitzel(imgUrl.Path, "tmpimg.jpg"); if (res) { IsSchnitzelLabel.Text = "Yes, it's a Schnitzel!"; GreenCImg.Hidden = false; } else { IsSchnitzelLabel.Text = "Nope, it's not a Schnitzel"; RedXImg.Hidden = false; } } finally { LoadingLabel.Hidden = true; LoadingIndicator.Hidden = true; } }; //imagePicker.Canceled += OnImagePickerCancelled; // Present UIImagePickerController; UIWindow window = UIApplication.SharedApplication.KeyWindow; var viewController = window.RootViewController; viewController.PresentModalViewController(imagePicker, true); }
private async void Button_Click(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapImage bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(fileStream); SelectedImage.Source = bitmapImage; } var schnitzelDetector = new SchnitzelDetector("AKIAJFHV4ILY7OS5LALQ", "cmxRYkx/cNY2iyW5fvi3Hy8o3+RK8nPJcbehfJ34"); try { IsLoading.Visibility = Visibility.Visible; ResultTb.Text = ""; var result = await schnitzelDetector.IsSchnitzel(file.Path, file.Name); if (result) { ResultTb.Text = "It's a schnitzel!!"; } else { ResultTb.Text = "Nope, it's not a schnitzel"; } } finally { IsLoading.Visibility = Visibility.Collapsed; } }
static void Main(string[] args) { //NOT: wiener-schnitzel.jpg, default-img-101715.jpg, //YES: wiener-schnitzel (1).jpg, Wiener-Schnitzel-1A-49a1616656a6c.jpg, Schnitzel-Wiener-Art.jpg SchnitzelDetector schnitzelDetector = new SchnitzelDetector(); //TODO: Add secret Key var fileName = "Schnitzel-Wiener-Art.jpg"; if (schnitzelDetector.IsSchnitzel(fileName, fileName).Result == true) { Console.WriteLine("This is a Schnitzel!"); } else { Console.WriteLine("This is not a Schnitzel!"); } Console.WriteLine("Hello World!"); Console.ReadKey(); }