private async Task SelectFromLibrary() { var options = new PickMediaOptions { PhotoSize = PhotoSize.Medium }; var photo = await CrossMedia.Current.PickPhotoAsync(options); }
private async void ButtonPickImage_OnClicked(object sender, EventArgs e) { PickMediaOptions pmo = new PickMediaOptions() { CompressionQuality = 100, SaveMetaData = true, ModalPresentationStyle = MediaPickerModalPresentationStyle.OverFullScreen }; var pickedImage = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(pmo); if (_files is null) { _files = new List <MediaFile>() { pickedImage }; } else { if (_files.Count == 4) { return; } _files.Add(pickedImage); } canvasViews.InvalidateSurface(); }
private async void Button_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Greška", "Učitavanje slike nije dozvoljeno", "OK"); return; } PickMediaOptions pick = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; var file = await CrossMedia.Current.PickPhotoAsync(pick); if (file == null) { return; } Image i = (Image)FindByName("Slika"); i.Source = ImageSource.FromStream(() => file.GetStream()); MemoryStream ms = new MemoryStream(); file.GetStream().CopyTo(ms); model._posiljaocSlika = ms.ToArray(); }
public async void ToolbarItem_Clicked(object sender, EventArgs e) { // establish communication between native project and media plugn await CrossMedia.Current.Initialize(); // take picture // !Creoss.Current.ISCameraAvailable // select picture if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Not Supported", "Your device does not currently support this functionality.", "Ok"); return; } var MediaOption = new PickMediaOptions() { PhotoSize = PhotoSize.Custom, CustomPhotoSize = 92, }; var SelectImageFile = await CrossMedia.Current.PickPhotoAsync(MediaOption); if (selectedImage == null) { await DisplayAlert("Error", "Could not get the image, please try again ", "Ok"); } selectedImage.Source = ImageSource.FromStream(() => SelectImageFile.GetStream()); }
async void Handle_Clicked(object sender, System.EventArgs e) { var response = await DisplayActionSheet("Profile Photo Source", "Cancel", null, "Camera", "Photo Album", "Remove"); if (response == "Camera") { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("No Camera", ":( No camera available.", "Got It"); return; } var mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions() { AllowCropping = true }); profilePicture.Source = ImageSource.FromStream(() => mediaFile.GetStream()); } else if (response == "Photo Album") { var pickerOptions = new PickMediaOptions(); var file = await CrossMedia.Current.PickPhotoAsync(pickerOptions); profilePicture.Source = ImageSource.FromStream(() => file.GetStream()); } else if (response == "Remove") { } }
private async void TakePhoto(object sender, EventArgs e) { try { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported || !CrossMedia.Current.IsTakePhotoSupported) { return; } var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; var selectedImageFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { AllowCropping = true, SaveToAlbum = true }); if (selectedImage == null) { ErrorCamera.Text = "Could not get the image , please try again!"; ErrorCamera.TextColor = Color.FromHex("#db6400"); await Task.Delay(2000); ErrorCamera.TextColor = Color.Transparent; } selectedImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream()); imagebyte = GetImageStreamAsBytes(selectedImageFile.GetStream()); } catch (Exception) { } }
// Photo Support // All the user to import a photo for the profile picture private async void photos() { await CrossMedia.Current.Initialize(); // Check for decive compatiablity if (!CrossMedia.Current.IsPickPhotoSupported) { await _pageService.DisplayAlert("Not Supported", "This device is not supported with this feature", "Ok"); } // set the size of the image var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Small }; var file = await CrossMedia.Current.PickPhotoAsync().ConfigureAwait(true); // set the Image URL to the file path of the photo on the phone try { Profile.ImageURL = file.Path; ProfileImageURL = file.Path; } catch (Exception e) { Console.WriteLine("No picture selected, leave blank"); } }
//Picture choose from device private async void BtnSelectPic_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "This is not support on your device.", "OK"); return; } else { var mediaOption = new PickMediaOptions() { PhotoSize = PhotoSize.MaxWidthHeight }; _mediaFile = await CrossMedia.Current.PickPhotoAsync(); if (_mediaFile == null) { return; } Stream stream1 = _mediaFile.GetStream(); Stream stream2 = _mediaFile.GetStream(); byte[] resizedImage1 = null; byte[] resizedImage2 = null; resizedImage1 = ResizeImage(stream1); resizedImage2 = ResizeImage(stream2); imageView.Source = ImageSource.FromStream(() => new MemoryStream(resizedImage1)); VM.User.ProfilePicture = resizedImage2; } }
public async Task <List <MediaFile> > PickPhotosAsync(PickMediaOptions options = null, MultiPickerOptions pickerOptions = null, CancellationToken token = default(CancellationToken)) { if (!await RequestStoragePermission()) { return(null); } var medias = await TakeMediasAsync("image/*", Intent.ActionPick, new StorePickerMediaOptions { MultiPicker = true }, token); if (options == null) { options = new PickMediaOptions(); } foreach (var media in medias) { //check to see if we picked a file, and if so then try to fix orientation and resize if (!string.IsNullOrWhiteSpace(media?.Path)) { try { await FixOrientationAndResize(options, media); } catch (Exception ex) { Console.WriteLine("Unable to check orientation: " + ex); } } } return(medias); }
private async void btnSelectPic_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "This is not support on your device.", "OK"); return; } else { var mediaOption = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; _mediaFile = await CrossMedia.Current.PickPhotoAsync(); if (_mediaFile == null) { return; } imgPreView.Source = ImageSource.FromStream(() => _mediaFile.GetStream()); UploadedUrl.Text = "Image URL:"; } }
private async void SelectImageButton_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "This is not supported on your device", "Ok"); return; } var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); if (selectedImageFile == null) { await DisplayAlert("Error", "There was an error when trying to get your image", "Ok"); return; } selectedImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream()); UploadImage(selectedImageFile.GetStream()); }
private async void btnSelectImage_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "This is not support on your device.", "OK"); return; } else { var mediaOption = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; _mediaFile = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions() { PhotoSize = PhotoSize.MaxWidthHeight, MaxWidthHeight = 600 }); if (_mediaFile == null) { return; } imgCoverImage.Source = ImageSource.FromStream(() => _mediaFile.GetStream()); } }
/// <summary> /// Picks a photo from the default gallery /// </summary> /// <returns>Media file or null if canceled</returns> public async Task <MediaFile> PickPhotoAsync(PickMediaOptions options = null, CancellationToken token = default(CancellationToken)) { if (!IsPickPhotoSupported) { throw new NotSupportedException(); } //Does not need permission on iOS 11 if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { CheckUsageDescription(photoDescription); await CheckPermissions(Permission.Photos); } var cameraOptions = new StoreCameraMediaOptions { PhotoSize = options?.PhotoSize ?? PhotoSize.Full, CompressionQuality = options?.CompressionQuality ?? 100, AllowCropping = false, CustomPhotoSize = options?.CustomPhotoSize ?? 100, MaxWidthHeight = options?.MaxWidthHeight, RotateImage = options?.RotateImage ?? true, SaveMetaData = options?.SaveMetaData ?? true, SaveToAlbum = false, ModalPresentationStyle = options?.ModalPresentationStyle ?? MediaPickerModalPresentationStyle.FullScreen, }; return(await GetMediaAsync(UIImagePickerControllerSourceType.PhotoLibrary, TypeImage, cameraOptions, token)); }
//Take picture from camera private async void Button_Clicked_2(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await DisplayAlert("Pas de Camera", ":(Aucune camera n'est disponible.)", "OK"); return; } else { _mediaFile = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { Directory = "Sample", Name = "myImage.jpg" }); imageView.Source = ImageSource.FromStream(() => _mediaFile.GetStream()); var mediaOption = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; UploadedUrl.Text = "Image URL:"; } }
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); var mediaOption = new PickMediaOptions() { PhotoSize = PhotoSize.Small }; var selectedImage = await CrossMedia.Current.PickPhotosAsync(mediaOption); var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync <StoragePermission>(); if (storageStatus == PermissionStatus.Granted && selectedImage != null) { for (int i = 0; i < selectedImage.Count; i++) { //AttachmentsImgLayer // .Children // .Add // (new Image // { // Source = // ImageSource.FromStream(() => selectedImage.ElementAt(i).GetStream()) // }); } } else { } }
/// <summary> /// Picks a photo from the default gallery /// </summary> /// <returns>Media file or null if canceled</returns> public async Task <MediaFile> PickPhotoAsync(PickMediaOptions options = null) { if (!(await RequestStoragePermission())) { return(null); } var media = await TakeMediaAsync("image/*", Intent.ActionPick, null); if (options == null) { options = new PickMediaOptions(); } //check to see if we picked a file, and if so then try to fix orientation and resize if (!string.IsNullOrWhiteSpace(media?.Path)) { try { await FixOrientationAndResizeAsync(media.Path, options.PhotoSize, options.CompressionQuality, options.CustomPhotoSize, options.RawFile); } catch (Exception ex) { Console.WriteLine("Unable to check orientation: " + ex); } } return(media); }
private static async Task <MediaFile> GetGalleryPhoto() { await CrossMedia.Current.Initialize(); var mediaOptions = new PickMediaOptions { PhotoSize = PhotoSize.Medium, CompressionQuality = 50 }; MediaFile file = null; try { file = await CrossMedia.Current.PickPhotoAsync(mediaOptions); } catch (MediaPermissionException e) { Debug.WriteLine($"Storage Permissions Not Authorized: {e.Message}"); } catch (Exception e) { Debug.WriteLine($"Storage Access Issue: {e.Message}"); } return(file); }
async Task FixOrientationAndResize(PickMediaOptions options, MediaFile media) { var originalMetadata = new ExifInterface(media.Path); if (options.RotateImage) { await FixOrientationAndResizeAsync(media.Path, options, originalMetadata); } else { await ResizeAsync(media.Path, options, originalMetadata); } if (options.SaveMetaData && IsValidExif(originalMetadata)) { try { originalMetadata?.SaveAttributes(); } catch (Exception ex) { Console.WriteLine($"Unable to save exif {ex}"); } } originalMetadata?.Dispose(); }
public async Task SelectPictureFromGallery() { var context = await _agentContextProvider.GetContextAsync(); await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await UserDialogs.Instance.AlertAsync("Not Supported", "Your device does not currently support this functionality", "Ok"); return; } var mediaOptions = new PickMediaOptions { PhotoSize = PhotoSize.MaxWidthHeight, CompressionQuality = 50, MaxWidthHeight = 200 }; var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); //AgentImageSource = ImageSource.FromStream(() => selectedImageFile.GetStream()); if (selectedImageFile != null) { _provisioningRecord.Owner.ImageUrl = ImageToBase64(selectedImageFile.Path); await _walletRecordService.UpdateAsync(context.Wallet, _provisioningRecord); _eventAggregator.Publish(new ApplicationEvent() { Type = ApplicationEventType.ProvisioningRecordUpdated }); } PopupNavigation.Instance.PopAsync(); }
/// <summary> /// Picks a photo from the default gallery /// </summary> /// <returns>Media file or null if canceled</returns> public async Task <MediaFile> PickPhotoAsync(PickMediaOptions options = null, CancellationToken token = default(CancellationToken)) { if (!(await RequestStoragePermission())) { throw new MediaPermissionException(Permission.Storage); } var media = await TakeMediaAsync("image/*", Intent.ActionPick, null, token); if (options == null) { options = new PickMediaOptions(); } //check to see if we picked a file, and if so then try to fix orientation and resize if (!string.IsNullOrWhiteSpace(media?.Path)) { try { await FixOrientationAndResize(options, media); } catch (Exception ex) { Console.WriteLine("Unable to check orientation: " + ex); } } return(media); }
private async void Button_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "Not supported", "Ok"); return; } var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); if (selectedImageFile == null) { await DisplayAlert("Error", "No image selected", "Ok"); return; } selectedImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream()); UploadImages(selectedImageFile.GetStream()); }
private async void UploadImageViaGallery() { await CrossMedia.Current.Initialize(); var pickMediaOptins = new PickMediaOptions() { MaxWidthHeight = 800, RotateImage = true }; var file = await CrossMedia.Current.PickPhotoAsync(pickMediaOptins); if (file == null) { return; } byte[] imageArray = System.IO.File.ReadAllBytes(file.Path);// convert path to byte array _imageSource = Convert.ToBase64String(imageArray); switch (Device.RuntimePlatform) { case Device.iOS: image.Source = ImageSource.FromFile(file.Path); break; case Device.Android: image.Source = file.Path; break; } }
async void Handle_Clicked(object sender, System.EventArgs e) { //! added using Plugin.Media; await CrossMedia.Current.Initialize(); //// if you want to take a picture use this // if(!CrossMedia.Current.IsTakePhotoSupported || !CrossMedia.Current.IsCameraAvailable) /// if you want to select from the gallery use this if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Not supported", "Your device does not currently support this functionality", "Ok"); return; } //! added using Plugin.Media.Abstractions; // if you want to take a picture use StoreCameraMediaOptions instead of PickMediaOptions var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; // if you want to take a picture use TakePhotoAsync instead of PickPhotoAsync var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); if (selectedImage == null) { await DisplayAlert("Error", "Could not get the image, please try again.", "Ok"); return; } selectedImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream()); UploadImage(selectedImageFile.GetStream()); }
private async void BtnGallerySignature_Clicked(object sender, EventArgs e) { try { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Not supported", "Your device does not currently support this functionality", "Ok"); return; } var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); if (imageProfile == null) { await DisplayAlert("Error", "Could not get the image, please try again.", "Ok"); return; } imageSignature.Source = ImageSource.FromStream(() => selectedImageFile.GetStream()); Preferences.Set(IMAGE_SIGNATURE, selectedImageFile.Path); } catch { imageProfile.Source = Preferences.Get(IMAGE_PROFILE, " "); } }
private async void PickImageFromGallery() { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsTakePhotoSupported) { await DisplayAlert("Oops", "Žao nam je, Vaš uređaj ne dozvoljava ovu funkcionalnost.", "OK"); return; } PickMediaOptions pick = new PickMediaOptions() { PhotoSize = PhotoSize.Small, CompressionQuality = 92 }; file = await CrossMedia.Current.PickPhotoAsync(pick); if (file == null) { return; } ImgProfile.Source = ImageSource.FromStream(() => file.GetStream()); AddImageToServer(); }
async void OnPickPhotoButtonClicked() { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "Not supported", "Ok"); return; } var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium }; var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); if (selectedImageFile == null) { await DisplayAlert("Error", "No image selected", "Ok"); return; } MyViewModel.AddImageToContact(selectedImageFile.Path); }
/// <summary> /// Picks a photo from the default gallery /// </summary> /// <returns>Media file or null if canceled</returns> public async Task <MediaFile> PickPhotoAsync(PickMediaOptions options = null) { if (!(await RequestStoragePermission())) { return(null); } var media = await TakeMediaAsync("image/*", Intent.ActionPick, null); if (options == null) { return(media); } //check to see if we need to rotate if success if (!string.IsNullOrWhiteSpace(media?.Path) && options.PhotoSize != PhotoSize.Full) { try { await FixOrientationAndResizeAsync(media.Path, options); } catch (Exception ex) { Console.WriteLine("Unable to check orientation: " + ex); } } return(media); }
public async void SelectImageButtonClicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Error", "This Is not supported on Your Device", "Ok"); return; } var mediaOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Medium //Change from very large }; var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions); //var Gallary = await CrossMedia.Current.; if (selectedImageFile == null && string.IsNullOrWhiteSpace(products.ImageUrl)) { await DisplayAlert("Error", "Select Image To Upload...", "Ok"); return; } if (string.IsNullOrWhiteSpace(products.ImageUrl)) { ImageSource.FromStream(() => selectedImageFile.GetStream()); selectedImageSource = selectedImageFile.Path; var sqlImageAlbumPath = selectedImageFile.AlbumPath; UpdateAndNavigate(); } if (!string.IsNullOrWhiteSpace(products.ImageUrl)) { if (selectedImageFile != null) { ImageSource.FromStream(() => selectedImageFile.GetStream()); selectedImageSource = selectedImageFile.Path; var sqlImageAlbumPath = selectedImageFile.AlbumPath; UpdateAndNavigate(); } else { selectedImageSource = products.ImageUrl; UpdateAndNavigate(); } } }
/// <summary> /// Setting Camera Options for Pick Photo /// </summary> /// <param name="options">PickMediaOptions from Media.Plugin</param> private void SetOptions(PickMediaOptions options, ref AppControl appControl) { if (appControl == null) { throw new ObjectDisposedException("AppControl"); } /// In Tizen, no options are available. Log.Info(LOG_TAG, "There is no option to supported"); }
public async Task <List <MediaFile> > PickPhotosAsync(PickMediaOptions options = null, MultiPickerOptions pickerOptions = null, CancellationToken token = default(CancellationToken)) { // TODO: complete Tizen implementation var result = await PickPhotoAsync(options, token); return(new List <MediaFile> { result }); }