private void EditRemote_Tapped(object sender, TappedRoutedEventArgs e) { var url = "http://imgstore.cdn.sogou.com/app/a/100540002/714860.jpg"; // create instance and show it ImageEditorControl editor = new ImageEditorControl(); editor.Show(new Uri(url)); //register event to get edited image editor.ImageEditedCompleted += (image_edited) => { image.Source = image_edited; }; }
//? This allows the image to be disposed when changing pages, otherwise it would just be loaded in the ImageEditorControl public async void LoadImage(ImageEditorControl parentEditorControl, string imagePath) { await Task.Run(() => { using (Image image = WallpaperManagerTools.GetImageFromFile(imagePath)) { if (image != null) // this will happen to unsupported file types { //! the image must be re-drawn to prevent it from being used by wallpaper manager //! which is why it needed to be put onto a bitmap //! don't change to image, if you do make sure to test what happens when an image is used & loaded simultaneously Bitmap imageBitmap = new Bitmap(image.Width, image.Height); using (Graphics g = Graphics.FromImage(imageBitmap)) g.DrawImage(image, 0, 0, image.Width, image.Height); loadedImageInfo.Add(imagePath, imageBitmap); //? Disposes images later (Whenever the page is changed) parentEditorControl.SetBackgroundImage(imageBitmap); } } }).ConfigureAwait(false); // ConfigureAwait(false) prevents a UI deadlock in the instance that the calling function needed to do LoadImage().Result }
private async void EditLocal_Tapped(object sender, TappedRoutedEventArgs e) { FileOpenPicker fo = new FileOpenPicker(); fo.FileTypeFilter.Add(".png"); fo.FileTypeFilter.Add(".jpg"); fo.SuggestedStartLocation = PickerLocationId.Desktop; var f = await fo.PickSingleFileAsync(); if (f != null) { // create instance and show it ImageEditorControl editor = new ImageEditorControl(); editor.Show(f); //register event to get edited image editor.ImageEditedCompleted += (image_edited) => { image.Source = image_edited; }; } }