![]() ![]() ![]() The pattern isn't obvious, however nor could you ever guess an RGB value given the position of your selection. If you take a few minutes to investigate the meaning of contiguous colors within the color-selection square, watching the values for the R, G, and B components of the color as you move the mouse about the screen, you'll be able to discern a pattern. Some development team arbitrarily selected the layout of the color grid on the right-hand side of Figure 1-there's no reason it has to look this way. Disregarding the alpha component, which will always be 255 (FF) when using this particular dialog box, it's easy to programmatically convert from the integer representation of the color to the color's individual bytes, hence the propensity for Windows, and therefore application developers, to use the RGB scheme to describe colors.Īlthough using the RGB color space does make it easier for the computer to convert back and forth between its internal representation of the color and the representation humans need in order to select a color, RGB doesn't provide any useful ordering of colors for selection. Breaking this 4-byte value up into individual bytes, you'll find, as you might expect given the color in Figure 1, the values 255, 48, 207, and 203 for the alpha, red, green, and blue components of the color. For example, with the color selected in Figure 1, the combined ARGB value is 13578293 decimal or FF30CFCB hex. The AlphaRGB (ARGB) value represents the color in a way that's easy for a computer to decipher. Note that the dialog box in Figure 1 doesn't provide any way to select an alpha component other than 255, allowing only fully opaque colors. The RGB color system combines three color coordinates, along with a value that indicates the transparency of the color that's often referred to as the "alpha" component of the color, and creates a 32-bit unsigned integer value that represents the color. The HSL values range from 0 to 240.įigure 1** Standard Color Selection in Windows ** In this dialog box, the individual RGB values contain 8-bit values and range from 0 all the way up to 255. Disregarding the left-hand side of the dialog box, which simply allows you to select from a palette of preselected colors, the right-hand pane allows you to drag the color selector with your mouse, or enter colors using two different color spaces, Red/Green/Blue (RGB) or Hue/Saturation/Luminosity (HSL). Figure 1 shows the standard Windows dialog box with the Define Custom Colors button selected, so the right-hand pane appears, allowing you to define your own colors. This representation of color choices is often called a "color space" because color representations normally allow you to refer to colors by a set of coordinates in three-dimensional space. The standard Windows color-selection dialog box represents colors in just two of the many ways you might represent colors in code. ![]() This article focuses on two specific areas: investigating different color-selection techniques and explaining the members of the System.Drawing namespace that make the sample application work. You can lay out the indicators just about any way you like, and the sample application includes two different layouts for the dialog box. The sample's layout and appearance are easy to modify. That is not true, however, and in this article I'll provide a simple-to-use replacement for the standard color-selection dialog box. Along the way, you'll get tips to help you use GDI+ in your own apps.īecause Windows® provides a standard common dialog box for selecting colors (see Figure 1) it's easy to assume that this is the only method for selecting colors. In this article, the author describes several color selection schemes, and uses GDI+ (via the System.Drawing namespace) to create a component that makes it possible for your own applications to provide a simpler, friendlier color chooser. For instance, the standard Windows color-selection dialog box allows you to work with the HSL color scheme in an indirect way. NETĪlthough most developers and APIs use the RGB scheme when working with colors, it's not the only available way to represent or select colors. ![]() This article assumes you're familiar with C# and Visual Basic. NET or C#Ĭode download available at: GDIColorPicker.exe(395 KB) A Primer on Building a Color Picker User Control with GDI+ in Visual Basic. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |