Exemplo n.º 1
0
        /// <summary>
        /// Clicking on the save button saves the photo in MainPage.ImageStream
        /// to media library camera roll. Once image has been saved, the
        /// application will navigate back to the main page.
        /// </summary>
        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex = FilterPreviewListView.SelectedIndex;

            DataContext dataContext = FilterEffects.DataContext.Instance;

            // Create the File Picker control
            var picker = new FileSavePicker();

            picker.FileTypeChoices.Add("JPG File", new List <string> {
                ".jpg"
            });
            StorageFile file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                // If the file path and name is entered properly, and user has not tapped 'cancel'..

                AbstractFilter filter = _filters[selectedIndex];
                IBuffer        buffer = await filter.RenderJpegAsync(
                    dataContext.FullResolutionStream.GetWindowsRuntimeBuffer());

                using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await stream.WriteAsync(buffer);

                    await stream.FlushAsync();
                }

                ShowToast(Strings.ImageSavedAs + file.Name);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the filters and creates the preview images.
        /// </summary>
        private async void CreatePreviewImagesAsync()
        {
            Debug.WriteLine(DebugTag + "CreatePreviewImages()");
            DataContext dataContext = FilterEffects.DataContext.Instance;

            if (dataContext.PreviewResolutionStream == null)
            {
                Debug.WriteLine(DebugTag + "No image (preview) stream available!");
                _navigationHelper.GoBack();
            }
            else
            {
                foreach (AbstractFilter filter in _filters)
                {
                    Debug.WriteLine(DebugTag + "CreatePreviewImages(): " + filter.Name);
                    filter.PreviewResolution = FilterEffects.DataContext.Instance.PreviewResolution;
                    filter.Buffer            = dataContext.PreviewResolutionStream.GetWindowsRuntimeBuffer();
                    filter.Apply();

                    if (filter is OriginalImageFilter)
                    {
                        AbstractFilter filter1 = filter;
                        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            PreviewImage.Source = filter1.PreviewImageSource;
                        });
                    }

                    _filterPreviewViewModel.Add(filter);
                }
            }

            FilterPreviewListView.SelectedIndex = 0;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Severes the connections related to showing and hiding the filter
        /// property controls and hides the controls if visible.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FilterPreviewPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = FilterPreviewPivot.SelectedIndex;

            Debug.WriteLine(DebugTag + "FilterPreviewPivot_SelectionChanged(): Index is " + index);

            if (!_hintTextShown && index != 0)
            {
                HintText.Visibility = Visibility.Visible;
                _hintTextShown      = true;
            }
            else if (_hintTextShown &&
                     HintText.Visibility == Visibility.Visible &&
                     index == 0)
            {
                HintText.Visibility = Visibility.Collapsed;
                _hintTextShown      = false;
            }

            ShowControlsAnimationStoryBoard.Completed -= ShowControlsAnimationStoryBoard_Completed;
            HideControlsAnimation.Completed           -= HideControlsAnimation_Completed;
            ShowControlsAnimationStoryBoard.Stop();
            HideControlsAnimationStoryBoard.Stop();

            FilterControlsContainer.Visibility = Visibility.Collapsed;
            FilterControlsContainer.Opacity    = 0;
            FilterControlsContainer.Children.Clear();

            AbstractFilter filter = _filters[index];

            if (filter.Control != null)
            {
                FilterControlsContainer.Children.Add(filter.Control);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Clicking on the save button opens a file picker, which prompts for
        /// the location where to save the image.
        /// </summary>
        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            ProgressIndicator.IsActive = true;
#if WINDOWS_PHONE_APP
            int selectedIndex = FilterPreviewPivot.SelectedIndex;
#else
            int selectedIndex = FilterPreviewListView.SelectedIndex;
#endif
            AbstractFilter filter      = _filters[selectedIndex];
            DataContext    dataContext = FilterEffects.DataContext.Instance;
            IBuffer        buffer      = await filter.RenderJpegAsync(
                dataContext.FullResolutionStream.GetWindowsRuntimeBuffer());

            FileManager fileManager = FileManager.Instance;
            bool        success     = await fileManager.SaveImageFileAsync(buffer);

            if (success)
            {
#if WINDOWS_PHONE_APP
                fileManager.ImageFileSavedResult += OnImageFileSavedResult;
#else
                // On Windows the image is already saved
                OnImageFileSavedResult(null, success);
#endif
            }
            else
            {
                ProgressIndicator.IsActive = false;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Clicking on the save button saves the photo in MainPage.ImageStream
        /// to media library camera roll. Once image has been saved, the
        /// application will navigate back to the main page.
        /// </summary>
        private async void SaveButton_Click(object sender, EventArgs e)
        {
            _progressIndicator.Text      = AppResources.SavingText;
            _progressIndicator.IsVisible = true;
            SystemTray.SetProgressIndicator(this, _progressIndicator);
            int selectedIndex = FilterPreviewPivot.SelectedIndex;

            DataContext dataContext = FilterEffects.DataContext.Instance;

            GC.Collect();

            try
            {
                if (selectedIndex == 0)
                {
                    using (MediaLibrary library = new MediaLibrary())
                    {
                        dataContext.FullResolutionStream.Position = 0;
                        library.SavePictureToCameraRoll(FileNamePrefix
                                                        + DateTime.Now.ToString() + ".jpg",
                                                        dataContext.FullResolutionStream);
                    }
                }
                else
                {
                    AbstractFilter filter = _filters[selectedIndex];

                    IBuffer buffer = await filter.RenderJpegAsync(
                        dataContext.FullResolutionStream.GetWindowsRuntimeBuffer());

                    using (MediaLibrary library = new MediaLibrary())
                    {
                        library.SavePictureToCameraRoll(FileNamePrefix
                                                        + DateTime.Now.ToString() + ".jpg", buffer.AsStream());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save the image: " + ex.ToString());
            }

            _progressIndicator.IsVisible = false;
            SystemTray.SetProgressIndicator(this, _progressIndicator);

            NavigationService.GoBack();
        }