Пример #1
0
        private static Bitmap CaptureDesktopScreen(ResolutionInformation bounds)
        {
            var desktopBmp = new Bitmap(bounds.Width, bounds.Height);
            var g          = Graphics.FromImage(desktopBmp);

            g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, new Size(bounds.Width, bounds.Height),
                             CopyPixelOperation.SourceCopy);
            g.Dispose();
            return(desktopBmp);
        }
 /*
 * Here we use regular binding handler to setup text based on current resolution information.
 */
 public override void ResolutionChanged(ResolutionInformation arg1)
 {
     if(arg1 != null) ResolutionText.text = string.Format("{0} x {1}", arg1.Width, arg1.Height);
 }
Пример #3
0
        private static List <DisplayInformation> UpdateDisplays()
        {
            var monitors = new List <DisplayInformation>();
            var d        = new DisplayDevice();

            d.cb = Marshal.SizeOf(d);
            try
            {
                for (uint id = 0; EnumDisplayDevices(null, id, ref d, 0); id++)
                {
                    if (d.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop))
                    {
                        var device = d.DeviceName;

                        var vDevMode             = new Devmode();
                        var i                    = 0;
                        var supportedResolutions = new Dictionary <string, List <ResolutionInformation> >();
                        while (EnumDisplaySettings(device, i, ref vDevMode))
                        {
                            var width         = vDevMode.dmPelsWidth;
                            var height        = vDevMode.dmPelsHeight;
                            var bpp           = vDevMode.dmBitsPerPel;
                            var orientation   = vDevMode.dmDisplayOrientation.ToString();
                            var freq          = vDevMode.dmDisplayFrequency;
                            var resolutionKey = $"{width}x{height}";
                            var resolution    = new ResolutionInformation
                            {
                                BitsPerPixel = bpp,
                                Frequency    = freq,
                                Height       = height,
                                Width        = width,
                                Orientation  = orientation
                            };
                            if (supportedResolutions.ContainsKey(resolutionKey))
                            {
                                supportedResolutions[resolutionKey].Add(resolution);
                            }
                            else
                            {
                                supportedResolutions.Add(resolutionKey, new List <ResolutionInformation>());
                                supportedResolutions[resolutionKey].Add(resolution);
                            }
                            i++;
                        }
                        var cDevMode = new Devmode();
                        EnumDisplaySettings(device, ENUM_CURRENT_SETTINGS, ref cDevMode);

                        var currentResolution = new ResolutionInformation
                        {
                            BitsPerPixel = cDevMode.dmBitsPerPel,
                            Frequency    = cDevMode.dmDisplayFrequency,
                            Height       = cDevMode.dmPelsHeight,
                            Width        = cDevMode.dmPelsWidth,
                            Orientation  = cDevMode.dmDisplayOrientation.ToString(),
                            X            = cDevMode.dmPositionX,
                            Y            = cDevMode.dmPositionY
                        };
                        var monitor = new DisplayInformation
                        {
                            Primary              = d.StateFlags.HasFlag(DisplayDeviceStateFlags.PrimaryDevice),
                            Attached             = d.StateFlags.HasFlag(DisplayDeviceStateFlags.AttachedToDesktop),
                            Removable            = d.StateFlags.HasFlag(DisplayDeviceStateFlags.Removable),
                            VgaCompatible        = d.StateFlags.HasFlag(DisplayDeviceStateFlags.VgaCompatible),
                            MirroringDriver      = d.StateFlags.HasFlag(DisplayDeviceStateFlags.MirroringDriver),
                            MultiDriver          = d.StateFlags.HasFlag(DisplayDeviceStateFlags.MultiDriver),
                            ModesPruned          = d.StateFlags.HasFlag(DisplayDeviceStateFlags.ModesPruned),
                            Remote               = d.StateFlags.HasFlag(DisplayDeviceStateFlags.Remote),
                            Disconnect           = d.StateFlags.HasFlag(DisplayDeviceStateFlags.Disconnect),
                            FriendlyName         = $"{GetAllMonitorsFriendlyNames().ElementAt((int)id)} on {d.DeviceString}",
                            SupportedResolutions = supportedResolutions,
                            CurrentResolution    = currentResolution,
                            DeviceName           = device
                        };
                        monitors.Add(monitor);
                        d.cb = Marshal.SizeOf(d);
                        EnumDisplayDevices(d.DeviceName, 0, ref d, 0);
                    }
                    d.cb = Marshal.SizeOf(d);
                }
                return(monitors);
            }
            catch
            {
            }
            string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;

            Console.WriteLine(errorMessage);
            return(monitors);
        }
 public virtual void ResolutionChanged(ResolutionInformation arg1) {
 }