public bool VerifySettings(out List <string> errors)
        {
            errors = new List <string>();

            if (ScreenshotsPath.IsEmpty())
            {
                errors.Add("Screenshots Folder Path must not be empty!");
            }

            var hotkeys = new HashSet <Hotkey>(new HotkeyComparer());

            if (!hotkeys.Add(CaptureFullscreenHotkey))
            {
                errors.Add("Duplicate hotkeys are not allowed!");
            }

            if (!hotkeys.Add(CaptureActiveMonitorHotkey))
            {
                errors.Add("Duplicate hotkeys are not allowed!");
            }

            if (!hotkeys.Add(CaptureActiveWindowHotkey))
            {
                errors.Add("Duplicate hotkeys are not allowed!");
            }

            return(errors.Count <= 0);
        }
        public ScreenshotPluginSettings(ScreenshotExtensionPlugin plugin)
        {
            _plugin = plugin;

            var savedSettings = plugin.LoadPluginSettings <ScreenshotPluginSettings>();

            if (savedSettings != null)
            {
                //SaveToGame = savedSettings.SaveToGame;
                //SaveToFolder = savedSettings.SaveToFolder;
                OnlyGameScreenshots        = savedSettings.OnlyGameScreenshots;
                ScreenshotsPath            = savedSettings.ScreenshotsPath;
                CaptureActiveMonitorHotkey = savedSettings.CaptureActiveMonitorHotkey;
                CaptureActiveWindowHotkey  = savedSettings.CaptureActiveWindowHotkey;
                CaptureFullscreenHotkey    = savedSettings.CaptureFullscreenHotkey;
            }

            if (ScreenshotsPath.IsEmpty())
            {
                ScreenshotsPath = Path.Combine(_plugin.PlayniteApi.Paths.ExtensionsDataPath, _plugin.Id.ToString());
            }
        }
示例#3
0
        private static void CaptureScreenArea(int x, int y, int width, int height)
        {
            // taking a picture of a viewport
            byte[,,] img = new byte[height, width, 3];
            GL.ReadPixels(x, y, width, height, OpenToolkit.Graphics.OpenGL4.PixelFormat.Rgb, PixelType.UnsignedByte, img);

            Console.WriteLine("Capturing screen...");
            System.Threading.Tasks.Task.Run(() =>
            {
                using (var bitmap = new Bitmap(width, height))
                {
                    // write all captured data to that bitmap
                    for (int i = 0; i < height; i++)
                    {
                        for (int j = 0; j < width; j++)
                        {
                            bitmap.SetPixel(j, height - 1 - i, Color.FromArgb(img[i, j, 0], img[i, j, 1], img[i, j, 2]));
                        }
                    }

                    // get the image format
                    string savepathLow  = ScreenshotsPath.ToLower();
                    string formatString = "";
                    for (int i = savepathLow.Length - 1; i >= 0; i--)
                    {
                        formatString += savepathLow[i];

                        if (savepathLow[i] == '.' || savepathLow[i] == '/' || savepathLow[i] == '\\')
                        {
                            break;
                        }
                    }

                    // reverse string to obtain the format
                    var chars = formatString.ToCharArray();
                    Array.Reverse(chars);
                    formatString = new string(chars);

                    // check format support
                    ImageFormat format   = ImageFormat.Bmp;
                    bool formatSpecified = true;
                    switch (formatString)
                    {
                    case ".bmp":
                        format = ImageFormat.Bmp;
                        break;

                    case ".jpg":
                    case ".jpeg":
                        format = ImageFormat.Jpeg;
                        break;

                    case ".png":
                        format = ImageFormat.Png;
                        break;

                    case ".gif":
                        format = ImageFormat.Gif;
                        break;

                    default:
                        formatSpecified = false;
                        break;
                    }

                    // save the obtained bitmap
                    if (formatSpecified)
                    {
                        bitmap.Save(ScreenshotsPath, format);
                    }
                    else
                    {
                        bitmap.Save(ScreenshotsPath + ".bmp", ImageFormat.Bmp);
                    }
                }
            });
        }