Пример #1
0
        //? 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
        }