Exemplo n.º 1
0
        /// <summary>
        /// Open a File Dialog, where the user can save a supported file type.
        /// </summary>
        internal static void SaveFiles()
        {
            string fileName;

            if (Pics.Count > 0)
            {
                if (string.IsNullOrEmpty(Pics[FolderIndex]))
                {
                    return;
                }
                fileName = Path.GetFileName(Pics[FolderIndex]);
            }
            else
            {
                fileName = Path.GetRandomFileName();
            }

            var Savedlg = new SaveFileDialog()
            {
                Filter   = FilterFiles,
                Title    = Application.Current.Resources["Save"] as string + $" - {SetTitle.AppName}",
                FileName = fileName
            };

            if (!Savedlg.ShowDialog().Value)
            {
                return;
            }

            IsDialogOpen = true;

            if (Pics.Count > 0)
            {
                if (!SaveImages.TrySaveImage(Rotateint, Flipped, Pics[FolderIndex], Savedlg.FileName))
                {
                    ShowTooltipMessage(Application.Current.Resources["SavingFileFailed"]);
                }
            }
            else
            {
                if (!SaveImages.TrySaveImage(Rotateint, Flipped, LoadWindows.GetMainWindow.MainImage.Source as BitmapSource, Savedlg.FileName))
                {
                    ShowTooltipMessage(Application.Current.Resources["SavingFileFailed"]);
                }
            }

            if (Savedlg.FileName == fileName)
            {
                //Refresh the list of pictures.
                Reload();
            }

            Close_UserControls();
            IsDialogOpen = false;
        }
Exemplo n.º 2
0
        internal static async Task SaveCrop()
        {
            var fileName = Pics.Count == 0 ? Path.GetRandomFileName()
                : Path.GetFileName(Pics[FolderIndex]);

            var Savedlg = new SaveFileDialog
            {
                Filter   = Open_Save.FilterFiles,
                Title    = $"{Application.Current.Resources["SaveImage"]} - {SetTitle.AppName}",
                FileName = fileName
            };

            if (!Savedlg.ShowDialog().Value)
            {
                return;
            }

            Open_Save.IsDialogOpen = true;

            var crop    = GetCrop();
            var success = false;

            if (Pics.Count > 0)
            {
                await Task.Run(() =>
                               success = SaveImages.TrySaveImage(
                                   crop,
                                   Pics[FolderIndex],
                                   Savedlg.FileName)).ConfigureAwait(false);
            }
            else
            {
                // Fixes saving if from web
                // TODO add working method for copied images
                var source = ConfigureWindows.GetMainWindow.MainImage.Source as BitmapSource;
                await Task.Run(() =>
                               success = SaveImages.TrySaveImage(
                                   crop,
                                   source,
                                   Savedlg.FileName)).ConfigureAwait(false);
            }
            await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke((Action)(() =>
            {
                if (!success)
                {
                    Tooltip.ShowTooltipMessage(Application.Current.Resources["SavingFileFailed"]);
                }

                ConfigureWindows.GetMainWindow.ParentContainer.Children.Remove(GetCropppingTool);
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set the desktop wallpaper.
        /// </summary>
        /// <param name="path">Path of the wallpaper</param>
        /// <param name="style">Wallpaper style</param>
        public static void SetDesktopWallpaper(string path, WallpaperStyle style)
        {
            // Set the wallpaper style and tile.
            // Two registry values are set in the Control Panel\Desktop key.
            // TileWallpaper
            //  0: The wallpaper picture should not be tiled
            //  1: The wallpaper picture should be tiled
            // WallpaperStyle
            //  0:  The image is centered if TileWallpaper=0 or tiled if TileWallpaper=1
            //  2:  The image is stretched to fill the screen
            //  6:  The image is resized to fit the screen while maintaining the aspect
            //      ratio. (Windows 7 and later)
            //  10: The image is resized and cropped to fill the screen while
            //      maintaining the aspect ratio. (Windows 7 and later)
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);

            switch (style)
            {
            case WallpaperStyle.Tile:
                key.SetValue(@"WallpaperStyle", "0");
                key.SetValue(@"TileWallpaper", "1");
                break;

            case WallpaperStyle.Center:
                key.SetValue(@"WallpaperStyle", "0");
                key.SetValue(@"TileWallpaper", "0");
                break;

            case WallpaperStyle.Stretch:
                key.SetValue(@"WallpaperStyle", "2");
                key.SetValue(@"TileWallpaper", "0");
                break;

            case WallpaperStyle.Fit:     // (Windows 7 and later)
                key.SetValue(@"WallpaperStyle", "6");
                key.SetValue(@"TileWallpaper", "0");
                break;

            default:
            case WallpaperStyle.Fill:     // (Windows 7 and later)
                key.SetValue(@"WallpaperStyle", "10");
                key.SetValue(@"TileWallpaper", "0");
                break;
            }

            key.Close();

            /// TODO Check if support for execotic file formats can be converted and
            /// works for Windows supported standard images, such as PSD to jpg?

            // If the specified image file is neither .bmp nor .jpg, - or -
            // if the image is a .jpg file but the operating system is Windows Server
            // 2003 or Windows XP/2000 that does not support .jpg as the desktop
            // wallpaper, convert the image file to .bmp and save it to the
            // %appdata%\Microsoft\Windows\Themes folder.
            string ext = Path.GetExtension(path);

            if ((!ext.Equals(".bmp", StringComparison.OrdinalIgnoreCase) &&
                 !ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase))
                ||
                (ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase) &&
                 !SupportJpgAsWallpaper))
            {
                var dest = string.Format(CultureInfo.CurrentCulture, @"{0}\Microsoft\Windows\Themes\{1}.jpg",
                                         Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                         Path.GetFileNameWithoutExtension(path));
                SaveImages.TrySaveImage(Rotateint, Flipped, path, dest);
                path = dest;
            }

            // Set the desktop wallpapaer by calling the Win32 API SystemParametersInfo
            // with the SPI_SETDESKWALLPAPER desktop parameter. The changes should
            // persist, and also be immediately visible.
            if (!NativeMethods.SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path,
                                                    SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE))
            {
                throw new Win32Exception();
            }
        }