コード例 #1
0
        private static void CheckScreenResolutions()
        {
            foreach (var screen in Screen.AllScreens)
            {
                double screenRes = (double)screen.Bounds.Size.Width / (double)screen.Bounds.Size.Height;

                ScreenShotInfo info = new ScreenShotInfo(screen);

                string resolution = String.Empty;

                if (Math.Abs(screenRes - StreamRes) < .001)
                {
                    resolution = "is 16:9";
                }
                else if (screenRes > StreamRes)
                {
                    resolution = "is wider than 16:9";
                }
                else if (screenRes < StreamRes)
                {
                    resolution = "is taller than 16:9";
                }

                Utilities.WriteLineWithTime($"Display '{screen.DeviceName}' {resolution} ({screen.Bounds.Size.Width}x{screen.Bounds.Size.Height}). Screen Shot Info: {info.Width}x{info.Height} capture. {info.XOffSet}x{info.YOffSet} offset.");
            }
        }
コード例 #2
0
        private static Bitmap CaptureScreen(Screen screen)
        {
            var ssInfo = new ScreenShotInfo(screen);

            //Create a new bitmap.
            var bmpScreenshot = new Bitmap(ssInfo.Width,
                                           ssInfo.Height,
                                           PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap.
            using (var gfxScreenshot = Graphics.FromImage(bmpScreenshot))
            {
                // Take the screenshot from the upper left corner to the right bottom corner.
                gfxScreenshot.CopyFromScreen(screen.Bounds.X + ssInfo.XOffSet,
                                             screen.Bounds.Y + ssInfo.YOffSet,
                                             0,
                                             0,
                                             new Size(ssInfo.Width, ssInfo.Height),
                                             CopyPixelOperation.SourceCopy);
            }

            return(bmpScreenshot);
        }