コード例 #1
0
        async Task <IEnumerable <RawEmotion> > CaptureEmotionAsync()
        {
            _isProcessing = true;

            RawEmotion[] result;

            try
            {
                var photoFile = await _photoService.CreateAsync();

                var imageProperties = ImageEncodingProperties.CreateBmp();
                await _mediaManager.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                result = await _emotionClient.RecognizeAsync(await photoFile.OpenStreamForReadAsync());
            }
            finally
            {
                await _photoService.CleanupAsync();

                _isProcessing = false;
            }

            return(result.IsNullOrEmpty()
                ? await Task.FromResult(Enumerable.Empty <RawEmotion>())
                : result);
        }
コード例 #2
0
        private async void btnTake_Click(object sender, RoutedEventArgs e)
        {
            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            StorageFile             file      = await ApplicationData.Current.LocalFolder.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);
        }
コード例 #3
0
        private async void capture_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                capture.IsEnabled = false;

                if (displayInformation.NativeOrientation == DisplayOrientations.Portrait)
                {
                    captureTransform.Rotation = 90.0;
                }

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                capture.IsEnabled = true;
                status.Log(capture, LocalizableStrings.CAMERA_CAPTURE_SUCCESS);

                IRandomAccessStream photoStream = await photoFile.OpenAsync(FileAccessMode.Read);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
            }
            catch (Exception ex)
            {
                status.Log(ex.Message);
            }
            finally
            {
                capture.IsEnabled = true;
            }
        }
コード例 #4
0
ファイル: ImageCapture.cs プロジェクト: vishalishere/msdnlive
        public async Task <WriteableBitmap> CaptureJpegImageAsync()
        {
            var bitmap = new WriteableBitmap(400, 300);

            using (var memoryStream = new InMemoryRandomAccessStream())
            {
                var file = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(IMAGECAPTURE_FILENAME, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                try
                {
                    await _mediaCapture.CapturePhotoToStorageFileAsync(_imageEncodingProperties, file);

                    var photoStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    await bitmap.SetSourceAsync(photoStream);

                    return(bitmap);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                return(null);
            }
        }
コード例 #5
0
        private async void CreateGroupButtonMethod()
        {
            faceServiceClient = new FaceServiceClient("fbeb228a7f1943b69c3e6e2861f22ff0");

            //var client = new HttpClient();
            //var queryString = WebUtility.UrlEncode(string.Empty);
            string personGroupId = "group1";
            Guid   personId      = new Guid("a3f0bd5c-b917-41f7-b50f-ae6fb2e3c6a2");
            //// Request header
            //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "fbeb228a7f1943b69c3e6e2861f22ff0");
            //var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/" + personGroupId + "/persons/"+ personId +"/persistedFaces" ;

            //HttpResponseMessage response;

            MediaCapture mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();

            photo = await KnownFolders.PicturesLibrary.CreateFileAsync(
                "capture1.jpg", CreationCollisionOption.ReplaceExisting);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photo);

            //Request body
            Stream image = await photo.OpenStreamForReadAsync();

            await faceServiceClient.AddPersonFaceAsync(personGroupId, personId, image);

            await faceServiceClient.TrainPersonGroupAsync(personGroupId);


            //var faces = await faceServiceClient.DetectAsync(image);
            //var faceIds = faces.Select(face => face.FaceId).ToArray();

            //var results = await faceServiceClient.IdentifyAsync(personGroupId, faceIds);
            //foreach (var identifyResult in results)
            //{
            //    if (identifyResult.Candidates.Length == 0)
            //    {

            //    }
            //    else
            //    {
            //        var candidateId = identifyResult.Candidates[0].PersonId;
            //        var person = await faceServiceClient.GetPersonAsync(personGroupId, candidateId);

            //    }
            //}
            //string body = JsonConvert.SerializeObject(new
            //{
            //    url =  photo.Path,
            //});
            //byte[] byteData = Encoding.UTF8.GetBytes(body);

            //using (var content = new ByteArrayContent(byteData))
            //{
            //    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            //    response = await client.PostAsync(uri, content);
            //}
        }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: kwhrkzk/Observation
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            CloudBlockBlob blockBlob = createBlob();

            MediaCapture mediaCaptureManager = new MediaCapture();

            mediaCaptureManager.InitializeAsync().ToObservable()
            .ObserveOnDispatcher()
            .SelectMany(_ =>
            {
                previewElement.Source = mediaCaptureManager;
                return(mediaCaptureManager.StartPreviewAsync().ToObservable());
            })
            .Subscribe(_ =>
            {
                Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync("tmp.jpg", Windows.Storage.CreationCollisionOption.ReplaceExisting).ToObservable()
                .Repeat()
                .Delay(TimeSpan.FromSeconds(5))
                .Subscribe(photoStorageFile =>
                {
                    Task.Run(async() => {
                        await mediaCaptureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);
                        await blockBlob.UploadFromFileAsync(photoStorageFile);
                    }).Wait();
                }, ex => Debug.WriteLine(ex.Message));
            });
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: Lubu909/UWP_Examples
        private async void previewElement_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Block multiple taps.
            if (!IsCaptureInProgress)
            {
                IsCaptureInProgress = true;

                // Create the temporary storage file.
                media = await ApplicationData.Current.LocalFolder
                        .CreateFileAsync("capture_file.jpg", CreationCollisionOption.ReplaceExisting);

                // Take the picture and store it locally as a JPEG.
                await cameraCapture.CapturePhotoToStorageFileAsync(
                    ImageEncodingProperties.CreateJpeg(), media);

                captureButtons.Visibility = Visibility.Visible;

                // Use the stored image as the preview source.
                BitmapImage tempBitmap = new BitmapImage(new Uri(media.Path));
                imagePreview.Source       = tempBitmap;
                imagePreview.Visibility   = Visibility.Visible;
                previewElement.Visibility = Visibility.Collapsed;
                IsCaptureInProgress       = false;
                ButtonRetake.Visibility   = Visibility.Visible;
            }
        }
コード例 #8
0
        public async void ImageCapture()
        {
            try
            {
                captureImage.Source = null;

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                status.Text = "Take Photo succeeded: " + photoFile.Path;
                //To preview capture image on UI
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;

                //To send Image to cloud
                await ImageUpload.UploadToAzure(photoFile, "mypic");
            }
            catch (Exception ex)
            {
                status.Text = ex.Message;
            }
        }
コード例 #9
0
ファイル: MainPage.xaml.cs プロジェクト: Skylarius/CellarDoor
        //GENERAL PURPOSE FUNCTION
        ///<summary>
        ///     Takes photo, saves photo file on temp folder, sets a place of grid as new photo and then returns user with attribute PhotoFace.
        ///</summary>
        private async Task <User> TakePhoto(String filename)
        {
            var photoFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

            await _mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateBmp(), photoFile);

            IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(photoStream);
            Image img = new Image()
            {
                Width = 100, Source = bitmap
            };

            //Add photo to grid

            photoContainer.Children.Add(img);
            Grid.SetRow(img, photoContainer.RowDefinitions.Count - 1);
            Grid.SetColumn(img, photoContainer.ColumnDefinitions.Count - 1);

            User u = new User();

            u.PhotoFace = img;
            await Print("Picture taken!");

            return(u);
        }
コード例 #10
0
        /// <summary>
        /// Takes a picture from the webcam
        /// </summary>
        /// <returns>StorageFile of image</returns>
        public async Task <StorageFile> TakePicture()
        {
            try
            {
                //captureImage is our Xaml image control (to preview the picture onscreen)
                CaptureImage.Source = null;

                //gets a reference to the file we're about to write a picture into
                StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    "RaspPiSecurityPic.jpg", CreationCollisionOption.GenerateUniqueName);

                //use the MediaCapture object to stream captured photo to a file
                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await MediaCap.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                //show photo onscreen
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                CaptureImage.Source = bitmap;

                AppStatus.Text = "Took Photo: " + photoFile.Name;

                return(photoFile);
            }
            catch (Exception ex)
            {
                //write the exception on screen
                AppStatus.Text = "Error taking picture: " + ex.Message;

                return(null);
            }
        }
コード例 #11
0
        /// <summary>
        /// 画像取得.
        /// </summary>
        private void capture()
        {
            MediaCapture mediaCaptureManager = new MediaCapture();

            mediaCaptureManager.InitializeAsync()
            .ToObservable()
            .ObserveOnDispatcher()
            .SelectMany(_ =>
            {
                previewElement.Source = mediaCaptureManager;
                return(mediaCaptureManager.StartPreviewAsync().ToObservable());
            })
            .Subscribe(_ =>
            {
                Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync("tmp.jpg", Windows.Storage.CreationCollisionOption.ReplaceExisting)
                .ToObservable()
                .Repeat()
                .Delay(TimeSpan.FromSeconds(10))
                .Subscribe(photoStorageFile =>
                {
                    Task.Run(async() => {
                        await mediaCaptureManager.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);

                        await getStorageSasUriAsync();

                        await putStorageFileAsync(photoStorageFile);

                        await notificationFileUploadAsync();
                    }).Wait();
                }, ex => Debug.WriteLine(ex.Message));
            });
        }
コード例 #12
0
        private async Task UploadPhoto()
        {
            photoUploadTimer.Stop();
            photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(capturedPhotoFile, CreationCollisionOption.ReplaceExisting);

            var imageProperties = ImageEncodingProperties.CreateJpeg();

            try
            {
                using (var fileStream = await photoStorageFile.OpenStreamForReadAsync())
                {
                    await mediaCaptureManager.CapturePhotoToStorageFileAsync(imageProperties, photoStorageFile);

                    var fileName = "img" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                    await deviceClient.UploadToBlobAsync(fileName, fileStream);

                    Debug.WriteLine(string.Format("Uploaded: {0} at {1}", fileName, DateTime.Now.ToString("yyyy/MM/dd - hh:mm:ss")));
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
            }
            photoUploadTimer.Start();
        }
コード例 #13
0
ファイル: PictureView.xaml.cs プロジェクト: ifabric/IoTLock
        private async Task <StorageFile> TakePicture()
        {
            try
            {
                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.ReplaceExisting);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                          () =>
                {
                    statusLabel.Text = "Photo taken";
                });

                return(photoFile);
                //IRandomAccessStream photoStream = await photoFile.OpenReadAsync();
                //BitmapImage bitmap = new BitmapImage();
                //bitmap.SetSource(photoStream);
            }
            catch (Exception ex)
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                          () =>
                {
                    statusLabel.Text = ex.Message;
                });

                return(null);
            }
        }
コード例 #14
0
ファイル: UsbCamera.cs プロジェクト: bethoma/securitysystem
        private async Task TakePhotoAsync()
        {
            if (!this.isEnabled)
            {
                return;
            }

            //Use current time in ticks as image name
            string imageName = DateTime.UtcNow.Ticks.ToString() + ".jpg";

            //Get folder to store images
            var cacheFolder = KnownFolders.PicturesLibrary;

            cacheFolder = await cacheFolder.GetFolderAsync("securitysystem-cameradrop");

            //Create blank file to store image
            StorageFile image = await cacheFolder.CreateFileAsync(imageName);

            try
            {
                //Capture an image and store it in the given file
                await mediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), image);
            }
            catch (Exception ex)
            {
                //Expected Exception. If image capture was unsuccessful, delete the blank file created
                await image.DeleteAsync();
            }
        }
コード例 #15
0
        private async Task <string> ScanAndDecodeImage()
        {
            Result result = null;

            while (result == null && IsPreviewing)
            {
                // TODO capture to stream instead
                //using (var stream = new InMemoryRandomAccessStream()) {
                //await MediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
                var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync("beam.jpg", CreationCollisionOption.GenerateUniqueName);

                await MediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), photoStorageFile);

                using (var stream = await photoStorageFile.OpenReadAsync()) {
                    // initialize with 1,1 to get the current size of the image
                    var writeableBmp = new WriteableBitmap(1, 1);
                    writeableBmp.SetSource(stream);
                    // and create it again because otherwise the WB isn't fully initialized and decoding
                    // results in a IndexOutOfRange
                    writeableBmp = new WriteableBitmap(writeableBmp.PixelWidth, writeableBmp.PixelHeight);
                    stream.Seek(0);
                    await writeableBmp.SetSourceAsync(stream);

                    result = DecodeBitmap(writeableBmp);
                }
                await photoStorageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);

                //}
            }
            return(result != null ? result.Text : null);
        }
コード例 #16
0
ファイル: MainPage.xaml.cs プロジェクト: microsoft/Coding4Fun
        private async void TakePhotoButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            try
            {
                Debug.WriteLine("Taking photo");
                TakePhotoButton.IsEnabled = false;

                //store the captured image
                _photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("capturedImage", CreationCollisionOption.ReplaceExisting);

                Debug.WriteLine("Create photo file successful");

                //create the properties to write
                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await _mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, _photoFile);

                TakePhotoButton.IsEnabled = true;
                Debug.WriteLine("Photo taken");

                //map the captured image as Bitmap image to the right column
                ImageElement.Source = await OpenImageAsBitmapAsync(_photoFile);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
                TakePhotoButton.IsEnabled = true;
            }
        }
コード例 #17
0
        private async void ImageUpload(string deviceId)
        {
            try
            {
                using (Windows.Storage.Streams.InMemoryRandomAccessStream captureStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
                {
                    await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream);

                    await captureStream.FlushAsync();

                    captureStream.Seek(0);

                    // Drops file onto device file system for debugging only
#if DEBUG
                    IStorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("Timelapse.jpg", CreationCollisionOption.ReplaceExisting);

                    ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                    await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);
#endif
                    LoggingService.Log("ImageUploadService Upload starting");
                    ImageUploadService.Upload(deviceId, captureStream);
                    LoggingService.Log("ImageUploadService Upload done");
                }
            }
            catch (Exception ex)
            {
                LoggingService.Error($"Image capture or upload failed ", ex);
            }
        }
コード例 #18
0
        private async Task takePhoto_Click()
        {
            try
            {
                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                //takePhoto.IsEnabled = true;
                //status.Text = "Take Photo succeeded: " + photoFile.Path;
                path = photoFile.Path;
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(photoStream);
                    captureImage.Source = bitmap;
                });

                TakeAndSendPicture(photoFile);
            }
            catch (Exception ex)
            {
                Cleanup();
            }
            finally
            {
            }
        }
コード例 #19
0
        private async void UploadImageButtonClick()
        {
            //CameraCaptureUI captureUI = new CameraCaptureUI();
            //captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            //captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            //photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            MediaCapture mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync();

            photo = await KnownFolders.PicturesLibrary.CreateFileAsync(
                "capture_file.jpg", CreationCollisionOption.ReplaceExisting);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photo);

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

            Status += "Image is Uploading...\n";
            SendToBlobAsync();
        }
コード例 #20
0
        private async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnTakePhoto.IsEnabled = false;
                captureImage.Source    = null;
                //store the captured image
                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                btnTakePhoto.IsEnabled = true;
                txtLocation.Text       = "Take Photo succeeded: " + photoFile.Path;
                //display the image
                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
                Picker_SelectedFile = photoFile;
                SelectFile();
            }
            catch (Exception ex)
            {
                txtLocation.Text = ex.Message;
                Cleanup();
            }
        }
コード例 #21
0
        private async Task <bool> TakePhoto_Click(object sender, TextChangedEventArgs e)
        {
            var files = await KnownFolders.PicturesLibrary.GetFilesAsync();

            var one = files.FirstOrDefault(x => x.Name == PHOTO_FILE_NAME);

            if (one != null)
            {
                await one.DeleteAsync();
            }
            StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                PHOTO_FILE_NAME, CreationCollisionOption.ReplaceExisting);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

            IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(photoStream);
            captureImage.Source = bitmap;
            photoStream.Dispose();

            using (Stream photoStream2 = await photoFile.OpenStreamForReadAsync())
            {
                await UploadFileToStorage(photoStream2, PHOTO_FILE_NAME);
            }

            return(true);
        }
コード例 #22
0
        private async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                takePhoto.IsEnabled   = false;
                recordVideo.IsEnabled = false;
                captureImage.Source   = null;

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                takePhoto.IsEnabled = true;
                status.Text         = "Take Photo succeeded: " + photoFile.Path;

                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
            }
            catch (Exception ex)
            {
                status.Text = ex.Message;
                Cleanup();
            }
            finally
            {
                takePhoto.IsEnabled   = true;
                recordVideo.IsEnabled = true;
            }
        }
コード例 #23
0
        async public void OnCapturesCommand(object param)
        {
            MediaCapture takePhotoManager = new MediaCapture();
            await takePhotoManager.InitializeAsync();

            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            IStorageFile            file      = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                "Photo.jpg", CreationCollisionOption.GenerateUniqueName);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);

            //Windows.Storage.StorageFile file = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

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

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(fileStream);

                IGraphInfo graph = this.Info as IGraphInfo;
                NodeVM     node  = new NodeVM();
                node.OffsetX    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportWidth) / 2;
                node.OffsetY    = ((this.Info as IGraph).ScrollSettings.ScrollInfo.ViewportHeight) / 2;
                node.UnitHeight = 100;
                node.UnitWidth  = 100;
                node.Content    = new Image()
                {
                    Source = bitmap, Stretch = Stretch.Fill
                };
                (Nodes as ObservableCollection <NodeVM>).Add(node);
            }
        }
コード例 #24
0
ファイル: MainPage.xaml.cs プロジェクト: drewby/DXHackathon
        private async void UploadPhoto()
        {
            uploadTimer.Stop();
            photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(capturedPhotoFile, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

            try
            {
                await mediaCaptureManager.CapturePhotoToStorageFileAsync(imageProperties, photoStorageFile);

                var cloudStorageAccount = CloudStorageAccount.Parse(AzureStorageConnString);
                var blobClient          = cloudStorageAccount.CreateCloudBlobClient();
                var container           = blobClient.GetContainerReference("photos");
                await container.CreateIfNotExistsAsync();

                var fileName  = "photo" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
                var blockBlob = container.GetBlockBlobReference(fileName);
                await blockBlob.UploadFromFileAsync(photoStorageFile);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            uploadTimer.Start();
        }
コード例 #25
0
ファイル: MainPage.xaml.cs プロジェクト: stephanhuewe/PiBuch
        private async void TakePhoto()
        {
            DeviceInformation cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Front);

            if (cameraDevice == null)
            {
                ErrorText.Text = "No camera";
                return;
            }

            MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings {
                VideoDeviceId = cameraDevice.Id
            };

            MediaCapture mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync(settings);

            StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("MyPhoto", CreationCollisionOption.GenerateUniqueName);

            ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();

            await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

            IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

            BitmapImage bitmap = new BitmapImage();

            bitmap.SetSource(photoStream);
            ImageControl.Source = bitmap;
        }
コード例 #26
0
        async void CapturePhoto()
        {
            var photoFolder = KnownFolders.CameraRoll;
            var photoFile   = await photoFolder.CreateFileAsync("photo.jpg", CreationCollisionOption.GenerateUniqueName);

            var photoEncoding = ImageEncodingProperties.CreateJpeg();
            await mediaCapture.CapturePhotoToStorageFileAsync(photoEncoding, photoFile);
        }
コード例 #27
0
ファイル: CameraCapture.cs プロジェクト: swinghu/AirStream
        public async Task <StorageFile> CapturePhoto(string desiredName = "photo.jpg")
        {
            var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(desiredName, CreationCollisionOption.GenerateUniqueName);

            await mediaCapture.CapturePhotoToStorageFileAsync(imgEncodingProperties, photoStorageFile);

            return(photoStorageFile);
        }
コード例 #28
0
        // method to take a still image, send to APIs, and display result
        public async void takePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                takePhoto.IsEnabled = false;

                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                takePhoto.IsEnabled = true;
                statusBox.Text      = "Take Photo succeeded: " + photoFile.Path;

                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                IRandomAccessStream photoStream2 = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                await writeableBitmap.SetSourceAsync(photoStream2);

                // and now for the face API call
                statusBox.Text = "Uploading image for Face API";

                Stream fs1 = await photoFile.OpenStreamForReadAsync();

                Stream fs2 = await photoFile.OpenStreamForReadAsync();

                var faceClient    = new FaceServiceClient("9725d03742394560be3ff295e1e435a2");
                var emotionClient = new EmotionServiceClient("c9306a1f134749759f1f4f9ae8838e1a");
                faceResult = await faceClient.DetectAsync(fs1);

                emotionResult = await emotionClient.RecognizeAsync(fs2);

                numFaces = faceResult.Length;

                statusBox.Text = "Number of faces detected: " + numFaces.ToString();
                currentFace    = 0;

                if (numFaces > 0) // if faces were returned in the result, display the first one
                {
                    displayFaceInfo();
                    displayImage();
                }
            }
            catch (Exception ex)
            {
                statusBox.Text = ex.Message;
                Cleanup();
            }
            finally
            {
                takePhoto.IsEnabled = true;
            }
        }
コード例 #29
0
        private async void MediaCapture_buttonPhoTo()
        {
            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();
            StorageFile             file      = await ApplicationData.Current.LocalFolder.CreateFileAsync("Photo.jpg", CreationCollisionOption.ReplaceExisting);

            await mediaCap.CapturePhotoToStorageFileAsync(imgFormat, file);

            mediaCapture.Status = "Photo";
        }
コード例 #30
0
        public async Task <StorageFile> CapturePhoto(string desiredName = "visit_photo.jpg")
        {
            // Create new unique file in the pictures library and capture photo into it
            var photoStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(desiredName, CreationCollisionOption.ReplaceExisting);

            await mediaCapture.CapturePhotoToStorageFileAsync(imgEncodingProperties, photoStorageFile);

            return(photoStorageFile);
        }