/// <summary>
        /// Gets the name for the cached version of the specified image.
        /// </summary>
        /// <param name="imagePath">The image path to cache.</param>
        /// <returns>The name of the associated cached image</returns>
        private string GetCachedImageName(string imagePath)
        {
            var desktopSize = DesktopHelper.GetPrimaryDesktopSize();

            var imageName = Path.GetFileNameWithoutExtension(imagePath)
                            + "."
                            + desktopSize.Width
                            + "x"
                            + desktopSize.Height
                            + "."
                            + File.GetLastWriteTime(imagePath).ToString("yyyyMMddhhmmss");

            if (ApplyMedianFilter)
            {
                imageName += ".median";
            }

            imageName += ".jpg";

            return(Path.Combine(Path.GetTempPath(), imageName));
        }
        /// <summary>
        /// Sets the current desktop wallpaper to the specified image.
        /// </summary>
        /// <param name="imagePath">The path of the image to set as the wallpaper.</param>
        public void SetWallpaper(string imagePath)
        {
            if (_settingWallpaper)
            {
                return;
            }
            if (!File.Exists(imagePath))
            {
                return;
            }

            _settingWallpaper = true;

            try
            {
                // get name cached
                var cachedImageName = GetCachedImageName(imagePath);

                // generate cached image if one doesn't exist
                if (!File.Exists(cachedImageName))
                {
                    var desktopSize = DesktopHelper.GetPrimaryDesktopSize();
                    var image       = Image.FromFile(imagePath);
                    ExifRotate(image);

                    Image wallpaper;

                    if (LandscapeOnly)
                    {
                        if (image.Width < image.Height)
                        {
                            _settingWallpaper = false;
                            ChangeWallpaper();
                            return;
                        }
                    }

                    var cropWallpaper = false;
                    if (desktopSize.Width > desktopSize.Height && image.Width > image.Height)
                    {
                        cropWallpaper = true;
                    }
                    else if (desktopSize.Width < desktopSize.Height && image.Width < image.Height)
                    {
                        cropWallpaper = true;
                    }

                    if (cropWallpaper)
                    {
                        wallpaper = ImageHelper.ScaleAndCropImageToFit(image, desktopSize);
                    }
                    else
                    {
                        var smallDesktopSize       = new Size(desktopSize.Width / 4, desktopSize.Height / 4);
                        var scaledBackgroundImage  = ImageHelper.ScaleAndCropImageToFit(image, smallDesktopSize);
                        var darkBackgroundImage    = ImageHelper.DarkenImage(scaledBackgroundImage, 0.5);
                        var blurredBackgroundImage = ImageHelper.BlurFilter(darkBackgroundImage, 10);

                        wallpaper = ImageHelper.ScaleAndCropImageToFit(blurredBackgroundImage, desktopSize);

                        var scaledImage = ImageHelper.ScaleImageToFit(image, desktopSize);

                        using (var graphics = Graphics.FromImage(wallpaper))
                        {
                            var x             = (desktopSize.Width - scaledImage.Width) / 2;
                            var y             = (desktopSize.Height - scaledImage.Height) / 2;
                            var imageLocation = new Point(x, y);
                            graphics.DrawImage(scaledImage, imageLocation);
                        }

                        scaledImage.Dispose();
                        scaledBackgroundImage.Dispose();
                        blurredBackgroundImage.Dispose();
                        darkBackgroundImage.Dispose();
                    }

                    if (ApplyMedianFilter)
                    {
                        using (var medianImage = ImageHelper.MedianFilter(wallpaper, 4))
                        {
                            medianImage.Save(cachedImageName, ImageFormat.Jpeg);
                        }
                    }
                    else
                    {
                        wallpaper.Save(cachedImageName, ImageFormat.Jpeg);
                    }


                    wallpaper.Dispose();

                    image.Dispose();
                }

                // get name for wallpaper bitmap in temp folder
                var wallpaperPath = Path.Combine(Path.GetTempPath(), "Wallpaper.bmp");

                // save cached image as wallpaper file and set as current wallpaper
                using (var image = Image.FromFile(cachedImageName))
                {
                    image.Save(wallpaperPath, ImageFormat.Bmp);
                }
                WallpaperHelper.SetWallpaper(wallpaperPath);

                // set as recent wallpaper
                CurrentWallpaperImage = imagePath;
                AddToRecentWallpaperList(imagePath);
            }
            catch (Exception e)
            {
                var message = $"Error setting wallpaper'{imagePath}'\r\n{e}";
                AddLogEntry(message);
                SaveLog();
            }
            finally
            {
                _settingWallpaper = false;
            }
        }