コード例 #1
0
        PixelFormat GetPixelFormatFromBitsPerPixel(ushort bitsPerPixel)
        {
            using (CrossThreadLogContext.Add(nameof(bitsPerPixel), bitsPerPixel))
            {
                switch (bitsPerPixel)
                {
                case 2:
                    return(PixelFormats.BlackWhite);

                case 8:
                    return(PixelFormats.Gray8);

                case 16:
                    return(PixelFormats.Gray16);

                case 24:
                    return(PixelFormats.Bgr24);

                case 32:
                    return(PixelFormats.Bgra32);

                default:
                    throw new InvalidOperationException("Could not recognize the pixel format.");
                }
            }
        }
コード例 #2
0
        void SpawnProcess(string uri, string workingDirectory, string arguments = null, string verb = null)
        {
            using (CrossThreadLogContext.Add("fileName", uri))
                using (CrossThreadLogContext.Add("workingDirectory", workingDirectory))
                    using (CrossThreadLogContext.Add("verb", verb))
                        using (CrossThreadLogContext.Add("arguments", arguments))
                        {
                            logger.Verbose("Launching {fileName} under verb {verb} in {workingDirectory} with arguments {arguments}.");

                            var process = Process.Start(
                                new ProcessStartInfo {
                                FileName         = uri,
                                WorkingDirectory = workingDirectory,
                                Verb             = verb,
                                Arguments        = arguments
                            });
                            processes.Add(process);
                        }
        }
コード例 #3
0
        public ScreenInformation GetActiveScreen()
        {
            var screens = Screen
                          .AllScreens
                          .Select(GetScreenInformationFromScreen)
                          .ToArray();

            var deviceMousePosition            = Control.MousePosition;
            var deviceIndependentMousePosition = pixelConversionService
                                                 .ConvertDeviceToDeviceIndependentPixels(
                new Vector(
                    deviceMousePosition.X,
                    deviceMousePosition.Y));

            using (CrossThreadLogContext.Add(nameof(deviceIndependentMousePosition), deviceIndependentMousePosition))
                using (CrossThreadLogContext.Add(nameof(screens), screens)) {
                    var activeScreen = screens.First(screen =>
                                                     screen.Bounds.X <= deviceIndependentMousePosition.X &&
                                                     screen.Bounds.Y <= deviceIndependentMousePosition.Y &&
                                                     screen.Bounds.X + screen.Bounds.Width >= deviceIndependentMousePosition.X &&
                                                     screen.Bounds.Y + screen.Bounds.Height >= deviceIndependentMousePosition.Y);
                    return(activeScreen);
                }
        }