private async void UploadButtonClick(object sender, RoutedEventArgs e)
        {
            (sender as Button).IsEnabled = false;

            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;

            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            var files = await picker.PickMultipleFilesAsync();

            var photos = new List <PhotoData>();

            if (files != null && files.Count > 0)
            {
                var folder = await AdventureObjectStorageHelper.GetDataSaveFolder();

                foreach (var file in files)
                {
                    var newFile = file;

                    if ((await file.GetParentAsync()).Path != folder.Path)
                    {
                        newFile = await file.CopyAsync(folder);
                    }

                    var photo = new PhotoData()
                    {
                        DateTime = DateTime.Now,
                        Uri      = newFile.Path,
                    };

                    //photo.ThumbnailUri = await VisionAPI.Instance.GetThumbnail(await newFile.OpenReadAsync(), newFile.DisplayName + "_thumb.jpg");

                    photos.Add(photo);
                }

                //await Data.Instance.SavePhotosAsync(photos);

                //Frame.Navigate(typeof(AdventurePage), null);
            }
            else
            {
                (sender as Button).IsEnabled = true;
            }
        }
Example #2
0
        public async Task <StorageFile> CapturePhotoAsync()
        {
            if (_mediaCapture == null)
            {
                return(null);
            }

            var stream = new InMemoryRandomAccessStream();

            await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

            try
            {
                var filename = "adventure_" + DateTime.Now.ToString("HHmmss_MMddyyyy") + ".jpg";

                var file = await(await AdventureObjectStorageHelper.GetDataSaveFolder()).CreateFileAsync(filename, CreationCollisionOption.GenerateUniqueName);

                using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var decoder = await BitmapDecoder.CreateAsync(stream);

                    var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);

                    var photoOrientation = ConvertOrientationToPhotoOrientation(GetCameraOrientation());
                    var properties       = new BitmapPropertySet {
                        { "System.Photo.Orientation", new BitmapTypedValue(photoOrientation, Windows.Foundation.PropertyType.UInt16) }
                    };

                    await encoder.BitmapProperties.SetPropertiesAsync(properties);

                    await encoder.FlushAsync();
                }

                stream.Dispose();
                PictureCaptured?.Invoke(this, new PictureCapturedEventArgs()
                {
                    File = file
                });
                return(file);
            }
            catch (Exception ex)
            {
                stream.Dispose();
                return(null);
            }
        }