Пример #1
0
        private async void TakePicture()
        {
            enroll_progressbar.Visibility = Visibility.Visible;
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            Size aspectRatio = new Size(16, 9);

            captureUI.PhotoSettings.CroppedAspectRatio  = aspectRatio;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(0, 0);
            captureUI.PhotoSettings.MaxResolution       = CameraCaptureUIMaxPhotoResolution.HighestAvailable;

            file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                enroll_progressbar.Visibility = Visibility.Collapsed;
                LoggingMsg("Load file success. Path: " + file.Path);
                //var stream = await file.OpenAsync(FileAccessMode.Read);
                //var image = new BitmapImage();
                //image.SetSource(stream);

                CheckFaceByRest();
            }
        }
        private async void BtnTake_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI capture = new CameraCaptureUI();

            capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            StorageFile file = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Album", CreationCollisionOption.OpenIfExists);

                string fileName = DateTime.Now.Ticks + ".jpg";
                await file.CopyAsync(folder, fileName, NameCollisionOption.ReplaceExisting);

                await file.DeleteAsync();

                file = await folder.GetFileAsync(fileName);

                FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);

                BitmapImage image = new BitmapImage();
                image.SetSource(stream);
                Photo.Source = image;
            }
        }
Пример #3
0
        public async void OtvoriKameru(Object slika)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo == null)
            {
                return;
            }

            IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);

            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

            SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

            SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
                                                                       BitmapPixelFormat.Bgra8,
                                                                       BitmapAlphaMode.Premultiplied);

            SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
            await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

            ((Image)slika).Source = bitmapSource;



            /* await(new MessageDialog("Vanjski uredjaj jos nije implementiran!")).ShowAsync();*/
            // Pokrece se web kamera da bi se korisnik uslikao
            // Vanjski uredjaj jos nije implementiran
        }
Пример #4
0
        private async void ContentDialog_TakePhoto_Clicked(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.AllowCropping = false;

            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo == null)
            {
                // User cancelled photo capture
                return;
            }

            // Otherwise we need to save the temporary file (after doing some clean up if we already have a file)
            if (TemporaryFile != null)
            {
                await TemporaryFile.DeleteAsync();
            }

            // Save off the photo
            TemporaryFile = photo;

            // Update the image
            BitmapImage            bitmapImage = new BitmapImage();
            FileRandomAccessStream stream      = (FileRandomAccessStream)await TemporaryFile.OpenAsync(FileAccessMode.Read);

            bitmapImage.SetSource(stream);
            image.Source = bitmapImage;
        }
Пример #5
0
        private async void Launch_Camera(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);

            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo == null)
            {
                // User cancelled photo capture
                return;
            }

            IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);

            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

            SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

            SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
                                                                       BitmapPixelFormat.Bgra8,
                                                                       BitmapAlphaMode.Premultiplied);

            SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
            await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

            Img.Source = bitmapSource;
        }
Пример #6
0
        private async void OpenCamera(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.AllowCropping       = true;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(300, 300);
            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

            var storageFile = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (storageFile == null)
            {
                //operação cancelada
            }
            else
            {
                using (var stream = await storageFile.OpenReadAsync())
                {
                    var bitmap = new BitmapImage();
                    await bitmap.SetSourceAsync(stream);

                    imgAvatar.Source = bitmap;
                }
            }
        }
Пример #7
0
        private async void newvideoBtn_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo
                CameraCaptureUI dialog = new CameraCaptureUI();
                dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;

                StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video);

                if (file != null)
                {
                    IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                    CapturedVideo.SetSource(fileStream, "video/mp4");

                    // Store the file path in Application Data
                    // Each time you Capture a video file.Path is a different, randomly generated path.
                    appSettings[videoKey] = file.Path;
                    filePath = file.Path;       // Set the global variable so when you record a video, that's that video that will send
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #8
0
        /*
         * Ezzel a függvénnyel tudjuk meghívni az eszköz kameráját és fényképet készíteni vele.
         * A fényképet átkonvertáljuk byte arraybe és bitmap imagebe is, ezek után pedig átadjuk őket arcdetektálásra és
         * a talált információk kiírására
         */
        public async void captureBtn(object sender, RoutedEventArgs e)
        {
            var captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(Canvas.Height, Canvas.Height);

            var photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                Stream stream = await photo.OpenStreamForReadAsync();

                Byte[] imagearray;

                using (var memoryStream = new MemoryStream())
                {
                    stream.CopyTo(memoryStream);
                    imagearray = memoryStream.ToArray();
                };

                BitmapImage image = new BitmapImage();
                using (InMemoryRandomAccessStream randomstream = new InMemoryRandomAccessStream())
                {
                    await randomstream.WriteAsync(imagearray.AsBuffer());

                    randomstream.Seek(0);
                    await image.SetSourceAsync(randomstream);
                }

                FaceDetectResponse[] faces = Detect(imagearray);
                displayFaces(faces, image);
            }
        }
Пример #9
0
        private async void Camera_Click(object sender, RoutedEventArgs e)
        {
            var capture = new CameraCaptureUI();

            capture.PhotoSettings.AllowCropping = true;
            capture.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.MediumXga;
            capture.VideoSettings.Format        = CameraCaptureUIVideoFormat.Mp4;
            capture.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.StandardDefinition;

            var file = await capture.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            if (file != null)
            {
                if (file.ContentType.Equals("video/mp4"))
                {
                    await file.CopyAsync(KnownFolders.CameraRoll, DateTime.Now.ToString("WIN_yyyyMMdd_HH_mm_ss") + ".mp4", NameCollisionOption.GenerateUniqueName);

                    ItemClick?.Invoke(this, new MediaSelectedEventArgs(await StorageVideo.CreateAsync(file, true), false));
                }
                else
                {
                    await file.CopyAsync(KnownFolders.CameraRoll, DateTime.Now.ToString("WIN_yyyyMMdd_HH_mm_ss") + ".jpg", NameCollisionOption.GenerateUniqueName);

                    ItemClick?.Invoke(this, new MediaSelectedEventArgs(await StoragePhoto.CreateAsync(file, true), false));
                }
            }
        }
        }         // End WebBrowser_Click

        // Method for taking a photo with the devices camera
        private async void Camera_Click(object sender, RoutedEventArgs e)
        {
            // If pin code has been entered correctly and menu has been unlocked
            if (MySplitView.IsPaneOpen == true)
            {
                CameraCaptureUI captureUI = new CameraCaptureUI();
                captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
                captureUI.PhotoSettings.CroppedSizeInPixels = new Size(300, 300);

                StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (photo == null)
                {
                    // User cancelled photo capture
                    return;
                }
                else
                {
                    // Save file to applicaitons local folder
                    await photo.CopyAsync(ApplicationData.Current.LocalFolder, photo.Name, NameCollisionOption.ReplaceExisting);
                }

                // If a file has been selected
                if (photo != null)
                {
                    // Navigate to page where image is displayed and label can be set
                    // Pass the file name along
                    this.Frame.Navigate(typeof(ImageDetails), photo.Name);
                } // End if
            }     // End if
        }         // End Camera_Click
Пример #11
0
        private async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (photo == null)
                {
                    //User cancelled photo
                    return;
                }
                else
                {
                    imageStream = await photo.OpenAsync(FileAccessMode.Read);

                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(imageStream);

                    SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                    SoftwareBitmap       softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                    SoftwareBitmapSource bitmapSource       = new SoftwareBitmapSource();
                    await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

                    image.Source = bitmapSource;
                }
            }
            catch
            {
                output.Text = "Error taking photo";
            }
        }
Пример #12
0
        private async void ExecuteTakePictureCommand()
        {
            try
            {
                Busy = true;

                StorageFile file = null;

                if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Media.Capture.CameraCaptureUI"))
                {
                    // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo
                    CameraCaptureUI dialog      = new CameraCaptureUI();
                    Size            aspectRatio = new Size(16, 9);
                    dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

                    file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
                }

                if (file != null)
                {
                    // Copy the file into local folder
                    await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);

                    // Save in the ToDoItem
                    TodoItem.ImageUri = new Uri("ms-appdata:///local/" + file.Name);
                }
            }
            finally { Busy = false; }
        }
Пример #13
0
        private async void image_Tapped(object sender, TappedRoutedEventArgs e)
        {
            try
            {
                CameraCaptureUI captureUI = new CameraCaptureUI();
                captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

                captureUI.PhotoSettings.CroppedSizeInPixels = new Size(1280, 720);

                photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

                stream = await photo.OpenAsync(FileAccessMode.Read);

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();

                SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
                                                                           BitmapPixelFormat.Bgra8,
                                                                           BitmapAlphaMode.Premultiplied);

                SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
                await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

                imgPhoto.Visibility = Visibility.Visible;
                imgPhoto.Source     = bitmapSource;
            }catch { }
        }
Пример #14
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            HttpClient client = new HttpClient();

            var uploadUrl = client.GetAsync("https://2-dot-backup-server-003.appspot.com/get-upload-token").Result.Content.ReadAsStringAsync().Result;

            Debug.WriteLine("Upload url: " + uploadUrl);



            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);



            this.photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);



            if (this.photo == null)

            {
                // User cancelled photo capture

                return;
            }

            HttpUploadFile(uploadUrl, "myFile", "image/png");
        }
        private async void EditCamera_Click(object sender, RoutedEventArgs e)
        {
            var capture = new CameraCaptureUI();

            capture.PhotoSettings.AllowCropping = false;
            capture.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.MediumXga;

            var file = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                var dialog = new EditYourPhotoView(file)
                {
                    CroppingProportions = ImageCroppingProportions.Square,
                    IsCropEnabled       = false
                };
                var dialogResult = await dialog.ShowAsync();

                if (dialogResult == ContentDialogBaseResult.OK)
                {
                    ViewModel.EditPhotoCommand.Execute(dialog.Result);
                }
            }
        }
Пример #16
0
        private async void takePhotoClick(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.AllowCropping = false;
            //captureUI.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.Large3M;

            StorageFile picture = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (picture != null)
            {
                var temp = Guid.NewGuid().ToString();
                await picture.CopyAsync(ApplicationData.Current.LocalFolder, temp, NameCollisionOption.ReplaceExisting);

                BitmapImage bitmapImage = new BitmapImage(new Uri("ms-appdata:///local/" + temp));
                photoImageDetail.Source = bitmapImage;

                IBuffer buffer = await FileIO.ReadBufferAsync(picture);

                using (DataReader dr = DataReader.FromBuffer(buffer))
                {
                    byte[] byte_Data = new byte[dr.UnconsumedBufferLength];
                    dr.ReadBytes(byte_Data);

                    MakeRequest(byte_Data);
                }
            }
        }
Пример #17
0
        public async void Camera()
        {
            // initiate camera app
            CameraCaptureUI cam = new CameraCaptureUI();

            cam.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            StorageFile imageFile = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (imageFile != null)
            {
                //Location of the picture taken from camera
                // var locator = new Geolocator();
                // Shows the user consent UI if needed
                var accessStatus = await Geolocator.RequestAccessAsync();

                if (accessStatus == GeolocationAccessStatus.Allowed)
                {
                    //   await GeotagHelper.SetGeotagFromGeolocatorAsync(imageFile, locator);
                }

                Images.Add(new photoModel()
                {
                    Path = new BitmapImage(new Uri(imageFile.Path)),
                    // Location = locator
                });
            }
        }
Пример #18
0
        private async void OpenCamera()
        {
            TopBarIsOpen = false;
            var dialog = new CameraCaptureUI();

            dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
            //dialog.VideoSettings.MaxDurationInSeconds = 45;
            dialog.VideoSettings.AllowTrimming = false;
            dialog.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.HighestAvailable;

            StorageFile videoFile = null;

            videoFile = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (videoFile == null)
            {
                return;
            }

            var stream = await videoFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

            var fileModel = new FileModel()
            {
                Name = "Live", Stream = stream, ContentType = "video/mp4"
            };

            NavigationModel.OpenFileModelCmd.Execute(fileModel);
        }
        private async void ClickButtonMakePhoto(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo == null)
            {
                return;
            }

            IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);

            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

            SoftwareBitmap bitmap = await decoder.GetSoftwareBitmapAsync();

            Language  ocrLanguage = new Language("en");
            OcrEngine ocrEngine   = OcrEngine.TryCreateFromUserProfileLanguages();
            OcrResult ocrResult   = await ocrEngine.RecognizeAsync(bitmap);

            string result = ocrResult.Text;

            Frame.Navigate(typeof(SelectTextAppoinmentPage), result);
        }
Пример #20
0
        /// <summary>
        ///  async private void CameraCapture()
        ///  Description:   Gets the captured image from the camera
        /// </summary>
        async private void CameraCapture()
        {
            CameraCaptureUI cameraUI = new CameraCaptureUI();

            cameraUI.PhotoSettings.AllowCropping = false;
            cameraUI.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.MediumXga;

            StorageFile capturedMedia = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (capturedMedia != null)
            {
                using (var streamCamera = await capturedMedia.OpenAsync(FileAccessMode.Read))
                {
                    BitmapImage bitmapImg = new BitmapImage();
                    bitmapImg.SetSource(streamCamera);

                    int width  = bitmapImg.PixelWidth;
                    int height = bitmapImg.PixelHeight;

                    WriteableBitmap writableBitmap = new WriteableBitmap(width, height);

                    using (var stream = await capturedMedia.OpenAsync(FileAccessMode.Read))
                    {
                        writableBitmap.SetSource(stream);
                        showClippedImages(bitmapImg);
                        randomAllPictures();
                    }
                }
            }
        }
Пример #21
0
        public async void OnRecordVideo()
        {
            var cam = new CameraCaptureUI();

            cam.VideoSettings.AllowTrimming = true;
            cam.VideoSettings.MaxResolution =
                CameraCaptureUIMaxVideoResolution.StandardDefinition;
            cam.VideoSettings.Format = CameraCaptureUIVideoFormat.Wmv;
            cam.VideoSettings.MaxDurationInSeconds = 5;
            StorageFile file = await cam.CaptureFileAsync(
                CameraCaptureUIMode.Video);

            if (file != null)
            {
                var picker = new FileSavePicker();
                picker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
                picker.FileTypeChoices.Add("Video File", new string[] { ".wmv" });
                StorageFile fileDestination = await picker.PickSaveFileAsync();

                if (fileDestination != null)
                {
                    await file.CopyAndReplaceAsync(fileDestination);
                }
            }
        }
Пример #22
0
        public async System.Threading.Tasks.Task clickbAsync()
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo == null)
            {
                return;
            }
            StorageFolder destinationFolder =
                await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfilePhotoFolder",
                                                                            CreationCollisionOption.OpenIfExists);

            await photo.CopyAsync(destinationFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting);

            await photo.DeleteAsync();

            //captureUI.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
            //StorageFile video = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
            //if (video == null)
            //{
            //    return;
            //}

            //mediaPlayerElement.Source = MediaSource.CreateFromStorageFile(video);
            //mediaPlayerElement.MediaPlayer.Play();
        }
Пример #23
0
        private async void BtnPhotoClick(object sender, RoutedEventArgs e)
        {
            var captureUi = new CameraCaptureUI();
            var photoFile = await captureUi.CaptureFileAsync(CameraCaptureUIMode.Photo);

            cropImage.SetSource(photoFile);
        }
Пример #24
0
        private async void CaptureVideo(object parameter)
        {
            if (!await VerifyCameraAvailable())
            {
                return;
            }

            try
            {
                CameraCaptureUI dialog = new CameraCaptureUI();
                dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;

                StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video);

                if (file != null)
                {
                    var fileName = string.Format("Video-{0}.mp4", Guid.NewGuid());
                    await file.MoveAsync(_localMediaFolder, fileName, NameCollisionOption.GenerateUniqueName);

                    var mediaItem = new MediaItem(FolderType.Local, ReservationId, file.Name);
                    MediaItems.Add(mediaItem);
                    SelectedMediaItem = mediaItem;
                }
            }
            catch (Exception ex)
            {
                ShowFatalErrorMessageDialog(ResourceHelper.ResourceLoader.GetString("CaptureVideo"), ResourceHelper.ResourceLoader.GetString("CaptureVideoError"));
            }
        }
Пример #25
0
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            // Capture image from camera
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(500, 500);
            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            // Setup http content using stream of captured photo
            IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);

            HttpStreamContent streamContent = new HttpStreamContent(stream);

            streamContent.Headers.ContentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/octet-stream");

            // Setup http request using content
            Uri apiEndPoint            = new Uri("https://api.projectoxford.ai/emotion/v1.0/recognize");
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, apiEndPoint);

            request.Content = streamContent;

            // Do an asynchronous POST.
            string     apiKey     = "1dd1f4e23a5743139399788aa30a7153"; //Replace this with your own Microsoft Cognitive Services Emotion API key from https://www.microsoft.com/cognitive-services/en-us/emotion-api. Please do not use my key. I include it here so you can get up and running quickly
            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
            HttpResponseMessage response = await httpClient.SendRequestAsync(request).AsTask();

            // Read response
            string responseContent = await response.Content.ReadAsStringAsync();

            // Display response
            textBlock.Text = responseContent;
        }
Пример #26
0
        private async void TakeVideo()
        {
            ShowPicture = false;
            ShowVideo   = true;

            var cameraCaptureUI = new CameraCaptureUI();

            cameraCaptureUI.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;

            var video = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (video != null)
            {
                _videoStream = await video.OpenAsync(FileAccessMode.Read);

                CapturedMedia = new MediaElement {
                    AutoPlay = true
                };
                CapturedMedia.Loaded += (sender, args) =>
                {
                    CapturedMedia.SetSource(_videoStream, "video/mp4");
                    CapturedMedia.Play();
                };
            }
        }
Пример #27
0
        private async void AddAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var         camera = new CameraCaptureUI();
            StorageFile file   = await camera.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                image.Source     = bitmapImage;
                this.DataContext = file;
                // Add picked file to MostRecentlyUsedList.
            }
            else
            {
                MessageDialog msgbox = new MessageDialog("Файл не выбран", "Внимание");
                await msgbox.ShowAsync();
            }
        }
Пример #28
0
        private async void openMyCamera()
        {
            CameraCaptureUI cameraUI = new CameraCaptureUI();

            cameraUI.PhotoSettings.AllowCropping = false;
            cameraUI.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.MediumXga;

            Windows.Storage.StorageFile capturedMedia =
                await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (capturedMedia != null)
            {
                using (var streamCamera = await capturedMedia.OpenAsync(FileAccessMode.Read))
                {
                    bitmapCamera = new BitmapImage();
                    bitmapCamera.SetSource(streamCamera);
                    //To display the image in a XAML image object, do this:
                    imagePreivew.Source = bitmapCamera;

                    // Convert the camera bitap to a WriteableBitmap object,
                    // which is often a more useful format.

                    int width  = bitmapCamera.PixelWidth;
                    int height = bitmapCamera.PixelHeight;

                    WriteableBitmap wBitmap = new WriteableBitmap(width, height);

                    using (var stream = await capturedMedia.OpenAsync(FileAccessMode.Read))
                    {
                        wBitmap.SetSource(stream);
                    }
                    SaveImageAsJpeg(wBitmap);
                }
            }
        }
Пример #29
0
        private static async Task <StorageFile> StorageFileFromCamera()
        {
            var dialog = new CameraCaptureUI();
            var file   = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);

            return(file);
        }
Пример #30
0
        private async void btnTakePhoto_Click(object sender, RoutedEventArgs e)
        {
            BitmapImage image = new BitmapImage();

            control_Image.Source = image;

            ccui.PhotoSettings.AllowCropping = true;
            ccui.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable;
            var photo = await ccui.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                var stream = await photo.OpenReadAsync();

                await image.SetSourceAsync(stream);

                stream.Seek(0);
                BinaryReader reader = new BinaryReader(stream.AsStreamForRead());
                user_image = new byte[stream.Size];
                reader.Read(user_image, 0, user_image.Length);
            }
            else
            {
                MessageDialog msg = new MessageDialog("We had a problem capturing your photo. Please try again.");
                await msg.ShowAsync();
            }
        }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!initialized)
                await Initialize();

            if (!IsCameraAvailable)
                throw new NotSupportedException();

            options.VerifyOptions();

            var capture = new CameraCaptureUI();
            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo, options);
            if (result == null)
                return null;
            
            StorageFolder folder = ApplicationData.Current.LocalFolder;

            string path = options.GetFilePath(folder.Path);
            var directoryFull = Path.GetDirectoryName(path);
            var newFolder = directoryFull.Replace(folder.Path, string.Empty);
            if (!string.IsNullOrWhiteSpace(newFolder))
                await folder.CreateFolderAsync(newFolder, CreationCollisionOption.OpenIfExists);

            folder = await StorageFolder.GetFolderFromPathAsync(directoryFull);

            string filename = Path.GetFileName(path);
            string aPath = null;
            if (options?.SaveToAlbum ?? false)
            {
                try
                {
                    string fileNameNoEx = Path.GetFileNameWithoutExtension(path);
                    var copy = await result.CopyAsync(KnownFolders.PicturesLibrary, fileNameNoEx + result.FileType, NameCollisionOption.GenerateUniqueName);
                    aPath = copy.Path;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("unable to save to album:" + ex);
                }
            }

            var file = await result.CopyAsync(folder, filename, NameCollisionOption.GenerateUniqueName).AsTask();
            return new MediaFile(file.Path, () => file.OpenStreamForReadAsync().Result, albumPath: aPath);
        }
Пример #32
0
    /// <summary>
    /// Take a photo async with specified options
    /// </summary>
    /// <param name="options">Camera Media Options</param>
    /// <returns>Media file of photo or null if canceled</returns>
    public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
    {
      if (!IsCameraAvailable)
        throw new NotSupportedException();

      options.VerifyOptions();

      var capture = new CameraCaptureUI();
      var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo, options);
      if (result == null)
        return null;

      StorageFolder folder = ApplicationData.Current.LocalFolder;

      string path = options.GetFilePath(folder.Path);
      var directoryFull = Path.GetDirectoryName(path);
      var newFolder = directoryFull.Replace(folder.Path, string.Empty);
      if (!string.IsNullOrWhiteSpace(newFolder))
        await folder.CreateFolderAsync(newFolder, CreationCollisionOption.OpenIfExists);

      folder = await StorageFolder.GetFolderFromPathAsync(directoryFull);

      string filename = Path.GetFileName(path);

      var file = await result.CopyAsync(folder, filename, NameCollisionOption.GenerateUniqueName).AsTask();
      return new MediaFile(file.Path, () => file.OpenStreamForReadAsync().Result);
    }