/// <summary> /// フォトライブラリ選択アクション /// </summary> /// <returns></returns> private async Task CommandTakeLibraryAction() { _takePhotoFromCamera = false; if (!CrossMedia.Current.IsPickPhotoSupported) { await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Error), LanguageUtils.Get(LanguageKeys.PictureLibraryCanNotOpen), LanguageUtils.Get(LanguageKeys.OK)); return; } var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions { PhotoSize = PhotoSize.Medium }); if (file == null) { return; } BodyImage = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); var imgData = ViewModelCommonUtil.ConvertToByteArrayFromStream(file.GetStream()); _base64String = Convert.ToBase64String(imgData); }
/*----------------------------------------------------------------------------------------------------------------------------------------*/ // // Command Actions // /*----------------------------------------------------------------------------------------------------------------------------------------*/ #region Command Actions /// <summary> /// カメラ撮影アクション /// </summary> /// <returns></returns> private async Task CommandTakeCameraAction() { _takePhotoFromCamera = true; try { // カメラが有効であるか判定 if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await Application.Current.MainPage.DisplayAlert(LanguageUtils.Get(LanguageKeys.Error), LanguageUtils.Get(LanguageKeys.CameraNotAvailable), LanguageUtils.Get(LanguageKeys.OK)); return; } // 画像ファイルの名前を決定 var fileName = BodyImageNameHead + ViewModelCommonUtil.FormatDateStringWithoutSymbol(DateTime.Now) + BodyImageExtension; var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { PhotoSize = PhotoSize.Medium, Directory = BodyImageFileDirectory, Name = fileName, SaveToAlbum = false }); if (file == null) { return; } _filePath = file.Path; BodyImage = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); var imgData = ViewModelCommonUtil.ConvertToByteArrayFromStream(file.GetStream()); _base64String = Convert.ToBase64String(imgData); } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }