Exemple #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);
            }
        }
        /// <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;
            }
        }
Exemple #3
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();
        }