示例#1
0
        private async Task GetItemsAsync()
        {
            // https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.image#Windows_UI_Xaml_Controls_Image_Source
            // See "Using a stream source to show images from the Pictures library".
            // This code is modified to get images from the app folder.

            // Get the app folder where the images are stored.
            StorageFolder appInstalledFolder = Package.Current.InstalledLocation;
            StorageFolder assets             = await appInstalledFolder.GetFolderAsync("Assets\\Samples");

            // Get and process files in folder
            IReadOnlyList <StorageFile> fileList = await assets.GetFilesAsync();

            foreach (StorageFile file in fileList)
            {
                // Limit to only png or jpg files.
                if (file.ContentType == "image/png" || file.ContentType == "image/jpeg")
                {
                    ImageFileInfo image = await LoadImageInfo(file);

                    if (!Images.Contains(image))
                    {
                        Images.Add(image);
                    }
                }
            }

            // Populate the new ImageGridView with the loaded images
            // Replaced with XAMl binding:
            // ImageGridView.ItemsSource = Images;
        }
        private async Task LoadSavedImageAsync(StorageFile imageFile, bool replaceImage)
        {
            item.NeedsSaved = false;
            var newItem = await MainPage.LoadImageInfo(imageFile);

            ResetEffects();

            // Get the index of the original image so we can
            // insert the saved image in the same place.
            var index = MainPage.Current.Images.IndexOf(item);

            item = newItem;
            this.Bindings.Update();

            UnloadObject(imgRect);
            FindName("imgRect");
            await LoadBrushAsync();

            // Insert the saved image into the collection.
            if (replaceImage == true)
            {
                MainPage.Current.Images.RemoveAt(index);
                MainPage.Current.Images.Insert(index, item);
            }
            else
            {
                MainPage.Current.Images.Insert(index + 1, item);
            }

            // Replace the persisted image used for connected animation.
            MainPage.Current.UpdatePersistedItem(item);
        }
示例#3
0
        private void ImageGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Prepare the connected animation for navigation to the detail page.
            persistedItem = e.ClickedItem as ImageFileInfo;
            ImageGridView.PrepareConnectedAnimation("itemAnimation", e.ClickedItem, "ItemImage");

            this.Frame.Navigate(typeof(DetailPage), e.ClickedItem);
        }
示例#4
0
        public async static Task <ImageFileInfo> LoadImageInfo(StorageFile file)
        {
            var properties = await file.Properties.GetImagePropertiesAsync();

            ImageFileInfo info = new ImageFileInfo(
                properties, file,
                file.DisplayName, file.DisplayType);

            return(info);
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            item = e.Parameter as ImageFileInfo;
            canNavigateWithUnsavedChanges = false;
            ImageSource = await item.GetImageSourceAsync();

            if (item != null)
            {
                ConnectedAnimation imageAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("itemAnimation");
                if (imageAnimation != null)
                {
                    targetImage.Source = ImageSource;

                    imageAnimation.Completed += async(s, e_) =>
                    {
                        await LoadBrushAsync();

                        // This delay prevents a flicker that can happen when
                        // a large image is being loaded to the brush. It gives
                        // the image time to finish loading. (200 is ok, 400 to be safe.)
                        await Task.Delay(400);

                        targetImage.Source = null;
                    };
                    imageAnimation.TryStart(targetImage);
                }

                if (ImageSource.PixelHeight == 0 && ImageSource.PixelWidth == 0)
                {
                    // There is no editable image loaded. Disable zoom and edit
                    // to prevent other errors.
                    EditButton.IsEnabled = false;
                    ZoomButton.IsEnabled = false;
                }
                ;
            }
            else
            {
                // error
            }

            if (this.Frame.CanGoBack)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }

            base.OnNavigatedTo(e);
        }
示例#6
0
        public async static Task <ImageFileInfo> LoadImageInfo(StorageFile file)
        {
            // Open a stream for the selected file.
            // The 'using' block ensures the stream is disposed
            // after the image is loaded.
            using (IRandomAccessStream fileStream = await file.OpenReadAsync())
            {
                // Create a bitmap to be the image source.
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.SetSource(fileStream);

                var properties = await file.Properties.GetImagePropertiesAsync();

                ImageFileInfo info = new ImageFileInfo(
                    properties, file, bitmapImage,
                    file.DisplayName, file.DisplayType);

                return(info);
            }
        }
示例#7
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            item = e.Parameter as ImageFileInfo;
            canNavigateWithUnsavedChanges = false;
            ResetEffects();

            if (item != null)
            {
                item.PropertyChanged += (s, e2) => UpdateEffectBrush(e2.PropertyName);
                targetImage.Source    = item.ImageSource;
                ConnectedAnimation imageAnimation = ConnectedAnimationService.GetForCurrentView().GetAnimation("itemAnimation");
                if (imageAnimation != null)
                {
                    imageAnimation.Completed += (s, e_) =>
                    {
                        MainImage.Source   = item.ImageSource;
                        targetImage.Source = null;
                    };
                    imageAnimation.TryStart(targetImage);
                }
            }
            else
            {
                // error
            }

            if (this.Frame.CanGoBack)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            }
            else
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
            }

            base.OnNavigatedTo(e);
        }
示例#8
0
 // If the image is edited and saved in the details page, this method gets called
 // so that the back navigation connected animation uses the correct image.
 public void UpdatePersistedItem(ImageFileInfo item)
 {
     persistedItem = item;
 }
示例#9
0
        private async void ExportImage()
        {
            CanvasDevice device = CanvasDevice.GetSharedDevice();

            using (CanvasRenderTarget offscreen = new CanvasRenderTarget(
                       device, item.ImageSource.PixelWidth, item.ImageSource.PixelHeight, 96))
            {
                using (IRandomAccessStream stream = await item.ImageFile.OpenReadAsync())
                    using (CanvasBitmap image = await CanvasBitmap.LoadAsync(offscreen, stream, 96))
                    {
                        saturationEffect.Source = image;
                        using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
                        {
                            ds.Clear(Windows.UI.Colors.Black);

                            // Need to copy the value of each effect setting.
                            contrastEffect.Contrast = item.Contrast;
                            exposureEffect.Exposure = item.Exposure;
                            temperatureAndTintEffect.Temperature = item.Temperature;
                            temperatureAndTintEffect.Tint        = item.Tint;
                            saturationEffect.Saturation          = item.Saturation;
                            graphicsEffect.BlurAmount            = item.Blur;
                            ds.DrawImage(graphicsEffect);
                        }

                        var fileSavePicker = new FileSavePicker()
                        {
                            SuggestedSaveFile = item.ImageFile
                        };

                        fileSavePicker.FileTypeChoices.Add("JPEG files", new List <string>()
                        {
                            ".jpg"
                        });

                        var outputFile = await fileSavePicker.PickSaveFileAsync();

                        if (outputFile != null)
                        {
                            using (IRandomAccessStream outStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
                            {
                                await offscreen.SaveAsync(outStream, CanvasBitmapFileFormat.Jpeg);
                            }

                            ResetEffects();
                            var newItem = await MainPage.LoadImageInfo(outputFile);

                            if (outputFile.Path == item.ImageFile.Path)
                            {
                                item.ImageSource = newItem.ImageSource;
                            }
                            else
                            {
                                item = newItem;
                            }

                            MainImage.Source = item.ImageSource;
                        }
                    }
            }
        }