colorpicker.md
1 # Color Picker 2 3 [Public overview - Microsoft Learn](https://learn.microsoft.com/en-us/windows/powertoys/color-picker) 4 5 ## Quick Links 6 7 [All Issues](https://github.com/microsoft/PowerToys/issues?q=is%3Aopen%20label%3A%22Product-Color%20Picker%22)<br> 8 [Bugs](https://github.com/microsoft/PowerToys/issues?q=is%3Aopen%20label%3AIssue-Bug%20label%3A%22Product-Color%20Picker%22)<br> 9 [Pull Requests](https://github.com/microsoft/PowerToys/pulls?q=is%3Apr+is%3Aopen++label%3A%22Product-Color+Picker%22) 10 11 ## Overview 12 Color Picker is a system-wide color picking utility for Windows that allows users to pick colors from any screen and copy them to the clipboard in a configurable format. 13 14 ## Implementation Details 15 16 ### Color Capturing Mechanism 17 The Color Picker works by following these steps to capture the color at the current mouse position: 18 19 1. Obtain the position of the mouse 20 2. Create a 1x1 size rectangle at that position 21 3. Create a Bitmap class and use it to initiate a Graphics object 22 4. Create an image associated with the Graphics object by leveraging the CopyFromScreen function, which captures the pixel information from the specified location 23 24 ### Core Color Picking Function 25 The following code snippet demonstrates the core functionality of how a color is picked from the screen: 26 27 ```csharp 28 private static Color GetPixelColor(System.Windows.Point mousePosition) 29 { 30 var rect = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); 31 using (var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb)) 32 { 33 var g = Graphics.FromImage(bmp); 34 g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy); 35 36 return bmp.GetPixel(0, 0); 37 } 38 } 39 ``` 40 41 ## Features 42 - Pick colors from any pixel on the screen 43 - View color information in various formats (RGB, HEX, HSL, etc.) 44 - Copy color values to clipboard in configurable formats 45 - Color history for quick access to previously selected colors 46 - Keyboard shortcuts for quick activation and operation 47 48 ## User Experience 49 When activated, Color Picker displays a magnified view of the area around the cursor to allow for precise color selection. Once a color is selected, it can be copied to the clipboard in the user's preferred format for use in design tools, development environments, or other applications.