private async Task TestMyMethod() { var dummy = new AnalyzingPage(new Models.ShoppingCart(), ImageSource.FromFile("balsh")); var path = Path.Combine(FileSystem.Current.LocalStorage.Path, "test/testreceiptImage.png"); var file = await EmbeddedResourceManager.CopyFileToLocation("receipt.png", path, true); await dummy.GetItemsFromImage(path); }
private async void OnCameraButtonClicked(object sender, EventArgs e) { if (!(await RequestPermissions())) { await DisplayAlert("Permission Denied", "Camera permissions are needed to continue.", "Ok"); return; } var photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()); if (photo == null) { await DisplayAlert("Error", "Could not save photo", "Ok"); return; } ShoppingCart cart = new ShoppingCart { DateCreated = DateTime.Now.ToFileTimeUtc() }; IFile photoFile = await FileSystem.Current.LocalStorage.CreateFileAsync(cart.ReceiptImageFilePath, CreationCollisionOption.ReplaceExisting); using (Stream writeStream = await photoFile.OpenAsync(PCLStorage.FileAccess.ReadAndWrite)) using (Stream readStream = photo.GetStream()) { await readStream.CopyToAsync(writeStream); } var photoSource = ImageSource.FromStream(() => { return(photo.GetStream()); }); var analyzingPage = new AnalyzingPage(cart, photoSource); await Navigation.PushAsync(analyzingPage); }
async Task OnAddClicked() { if (!(await RequestPermissions())) { await DisplayAlert("Permission Denied", "Camera permissions are needed to continue.", "Ok"); return; } const string cameraAction = "Camera"; const string storageAction = "Storage"; MediaFile photo = null; if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsPickPhotoSupported && CrossMedia.Current.IsCameraAvailable) { var choice = await DisplayActionSheet("Choose Source", "Cancel", null, new string[] { cameraAction, storageAction }); switch (choice) { case cameraAction: photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions() { CustomPhotoSize = 30 }); break; case storageAction: photo = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions() { CustomPhotoSize = 30 }); break; default: return; } } else if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsCameraAvailable) { photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions() { CustomPhotoSize = 30 }); } else if (CrossMedia.Current.IsPickPhotoSupported) { photo = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions() { CustomPhotoSize = 30 }); } else { await DisplayAlert("Error", "No image capture is available on this device.", "Ok"); } if (photo == null) { await DisplayAlert("Error", "Could not save photo", "Ok"); return; } ShoppingCart cart = new ShoppingCart { DateCreated = DateTime.Now.ToFileTimeUtc() }; IFile photoFile = await FileSystem.Current.LocalStorage.CreateFileAsync(cart.ReceiptImageFilePath, CreationCollisionOption.ReplaceExisting); using (Stream writeStream = await photoFile.OpenAsync(PCLStorage.FileAccess.ReadAndWrite)) using (Stream readStream = photo.GetStream()) { await readStream.CopyToAsync(writeStream); } var photoSource = ImageSource.FromStream(() => { return(photo.GetStream()); }); var analyzingPage = new AnalyzingPage(cart, photoSource); await Navigation.PushAsync(analyzingPage); }