Beispiel #1
0
        private void SetAsWallpaper()
        {
            string fileName = Path.GetTempPath() + "wallpaper";

            try
            {
                // Without specifying an extension, the default BMP encoder will be used. JPG also tested here.
                ImageEditing.SaveImage(mModifiedImage, fileName);

                if (GetIsWindows8())
                {
                    ShObjIdlCoreHelper.SetWallpaper(fileName, DESKTOP_WALLPAPER_POSITION.DWPOS_CENTER);
                }
                else
                {
                    LegacyWallpaperHelper.SetWallpaper(fileName, LegacyWallpaperHelper.Style.Centered);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show
                (
                    string.Format("Unable to set wallpaper.") +
                    Environment.NewLine +
                    string.Format("Error Information: {0}", e.Message),
                    "Error"
                );
            }
        }
Beispiel #2
0
        private void SavePicture()
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.InitialDirectory = Environment.CurrentDirectory;
            saveDialog.Filter           = ImageEditing.GetSupportedEncodersFilter();
            saveDialog.FilterIndex      = 1;
            saveDialog.DefaultExt       = "jpg";
            saveDialog.ValidateNames    = true;
            saveDialog.RestoreDirectory = false;

            // remove the extension from the name and add the new dimensions to the new name.
            saveDialog.FileName = BuildFileName
                                  (
                ((FileInfo)mOpenImage.Tag).Name,
                ((FileInfo)mOpenImage.Tag).Extension,
                "_" + mModifiedImage.Width + "x" + mModifiedImage.Height
                                  );

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ImageEditing.SaveImage(mModifiedImage, saveDialog.FileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show
                    (
                        string.Format("Unable to save {0}.", Path.GetFileName(saveDialog.FileName)) +
                        Environment.NewLine +
                        string.Format("Error Information: {0}", e.Message),
                        "Error"
                    );
                }
            }
        }