// CameraCaptureUI コントロールを使って撮影
        private async void buttonCameraCaptureUI_Click(object sender, RoutedEventArgs e)
        {
            // http://coelacanth.heteml.jp/blog/metrostyleapp%E5%85%A5%E9%96%80-vol33-%E3%82%AB%E3%83%A1%E3%83%A9%E3%81%A7%E6%92%AE%E5%BD%B1%E3%81%97%E3%81%9F%E7%94%BB%E5%83%8F%E3%82%92%E4%BF%9D%E5%AD%98%E3%81%99%E3%82%8B/

            // ダイアログ生成
            var dialog = new Windows.Media.Capture.CameraCaptureUI();

            // 写真のフォーマットを指定
            dialog.PhotoSettings.Format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.Png;

            //// クロップ枠を固定できる (縦横比だけ固定することも可能)
            //var size = new Size(500.0, 100.0);
            //dialog.PhotoSettings.CroppedSizeInPixels = size;
            ////dialog.PhotoSettings.CroppedAspectRatio = size;

            // 写真撮影モードでダイアログを起動
            var file = await dialog.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Photo);

            // 撮影できると、保存されたファイルの StorageFile が返ってくる。
            // 保存先は ApplicationData.Current.TemporaryFolder
            if (file != null)
            {
                var msgbox = new Windows.UI.Popups.MessageDialog(file.Path, "撮影結果");
                await msgbox.ShowAsync();
            }
        }
        public static async Task <StorageFile> CapturePhotoFileAsync()
        {
            var captureUi = new Windows.Media.Capture.CameraCaptureUI();

            captureUi.PhotoSettings.Format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.Jpeg;

            var file = await captureUi.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Photo);

            if (file != null)
            {
                var filename = Application.Current.Resources["PhotoCaptureTemporaryFilename"] as string;
                var folder   = ApplicationData.Current.TemporaryFolder;
                if (filename != null)
                {
                    var temporaryFile = await folder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                    CachedFileManager.DeferUpdates(temporaryFile);
                    await file.CopyAndReplaceAsync(temporaryFile);

                    await CachedFileManager.CompleteUpdatesAsync(temporaryFile);

                    file = temporaryFile;
                }
            }

            return(file);
        }
예제 #3
0
        public async void CaptureImage()
        {
            var dialog = new Windows.UI.Popups.MessageDialog("Would you like to use your camera or select a picture from your library?");
            dialog.Commands.Add(new Windows.UI.Popups.UICommand("I'd like to use my camera", null, "camera"));
            dialog.Commands.Add(new Windows.UI.Popups.UICommand("I already have the picture", null, "picker"));

            IStorageFile photoFile;
            var command = await dialog.ShowAsync();
            if ((string) command.Id == "camera")
            {
                var cameraCapture = new Windows.Media.Capture.CameraCaptureUI();
                photoFile = await cameraCapture.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Photo);
            }
            else
            {
                var photoPicker = new FileOpenPicker();
                photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                photoPicker.FileTypeFilter.Add(".png");
                photoPicker.FileTypeFilter.Add(".jpg");
                photoPicker.FileTypeFilter.Add(".jpeg");

                photoFile = await photoPicker.PickSingleFileAsync();
            }

            if (photoFile == null)
                return;

            var raStream = await photoFile.OpenAsync(FileAccessMode.Read);
            Customer.ImageStream = raStream.AsStream();
        }
예제 #4
0
        /// <summary>
        ///  カメラによる写真撮影を行う.
        /// </summary>
        private async void CaptureCameraAsync()
        {
            var cameraUI = new Windows.Media.Capture.CameraCaptureUI();
            var file     = await cameraUI.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Photo);

            if (file == null)
            {
                return;
            }
            await this.CameraCache.MoveAndAddAsync(file);

            await this.MainCanvas.SetImageAsync(file);
        }
예제 #5
0
        /// <summary>
        /// Create a new CameraCaptureUI object.
        /// </summary>
        public CameraCaptureUI()
        {
#if __IOS__
            Init();
#elif WINDOWS_UWP || WINDOWS_APP
            _cc = new Windows.Media.Capture.CameraCaptureUI();
#elif WINDOWS_PHONE_APP
            if (_type10 != null)
            {
                ccu = Activator.CreateInstance(_type10);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }
#elif WINDOWS_PHONE
            _task            = new CameraCaptureTask();
            _task.Completed += _task_Completed;
#endif
        }
        public static async Task<StorageFile> CapturePhotoFileAsync()
        {
            var captureUi = new Windows.Media.Capture.CameraCaptureUI();
            captureUi.PhotoSettings.Format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.Jpeg;

            var file = await captureUi.CaptureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.Photo);

            if (file != null)
            {
                var filename = Application.Current.Resources["PhotoCaptureTemporaryFilename"] as string;
                var folder = ApplicationData.Current.TemporaryFolder;
                var temporaryFile = await folder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                CachedFileManager.DeferUpdates(temporaryFile);
                await file.CopyAndReplaceAsync(temporaryFile);
                await CachedFileManager.CompleteUpdatesAsync(temporaryFile);

                file = temporaryFile;
            }

            return file;
        }