One primary use GDI + color pickup user control

xiaoxiao2021-03-06  115

summary

Although most developers and APIs use the RGB scheme when using colors in work, it is not the only way to use. For example, the standard Windows Color - Select Dialog Allows you to use an indirect method with an indirect method while working. This article describes a number of colors selected, and generates a component using GDI (via system.drawing namespace) to make a simple, friendly color selection for your own application. With this method, you will get some tips to help you use GDI in your own application.

Because Windows? Provides a standard generic to select a color dialog (see Figure 1), it is easy to assume that this is the only way to select color. That is incorrect, however, in this article I will provide an easy-to-use method to replace standard colors - Select dialog. The appearance and layout of this example is easy to modify. You can use any of your favorite methods to design the indicator, and this example contains two different layout design. This article is in two specific regions: how to study different color selection and explain how the system.drawing namespace makes this example work.

Color space:

Standard Windows Colors - Select Dialogs only provide two methods in many ways to represent colors. You can use the code to represent the color. The representation of this color selection is usually called "color space" because color representation usually allows you to access colors through a fixed three-dimensional coordinate space. Figure 1 shows the standard Windows dialog that is selected when the colors button is selected, so the right hand side panel appears, allowing you to define your own color. Ignore the dialog box on the side of the left hand, which allows you to simply select color through a palette of a pre-selected color, the right hand side panel allows the mouse to drag the color selection strip, or use two different color space, red / green / Blue (RGB) or Color / Saturated / Illumination (HSL) input colors. In this dialog, a single RGB value contains 8-bit value and the range from 0 until 255. HSL range from 0 to 240.

Figure 1 Color Selection dialog box for Windows Standard

The RGB color system combines three color coordinates, the same indicates the transparency of the color, commonly referred to as "alpha", generating a 32-bit unsigned integer value to represent color. Note Figure 1 This dialog does not provide any way to select an alpha value except 255, allowing only completely opaque colors. The alphargb (argb) value is a way to use a computer to represent a color. For example, in FIG. 1 selects a color, the combined Argb value is a decimal 13578293 or a hexadecimal number FF30CFCB. Based on the 4-byte value to make a single byte, you will find it, what you are looking forward to a given color in Figure 1, the value is 255, 48, 207, and 203 are Alpha , Red, green, and blue color components. When using this special dialog, ignore the Alpha section, it will always be 255 (ff), which will easily use the programming method to convert an integer to a single byte of a color, so Windows's enthusiasts and them Application developers, use the RGB solution to represent colors.

The RGB color system combines three color coordinates, the same indicates the transparency of the color, commonly referred to as "alpha", generating a 32-bit unsigned integer value to represent color. Note Figure 1 This dialog does not provide any way to select an alpha value except 255, allowing only completely opaque colors. The alphargb (argb) value is a way to use a computer to represent a color. For example, in FIG. 1 selects a color, the combined Argb value is a decimal 13578293 or a hexadecimal number FF30CFCB. Based on the 4-byte value to make a single byte, you will find it, what you are looking forward to a given color in Figure 1, the value is 255, 48, 207, and 203 are Alpha , Red, green, and blue color components. When using this special dialog, ignore the Alpha section, it will always be 255 (ff), which will easily use the programming method to convert an integer to a single byte of a color, so Windows's enthusiasts and them Application developers, use the RGB solution to represent colors. Although the RGB color space is used to transform color between its internal conversion and forward and indicating that human needs is relatively easy to select a color, there is no useful order in color picking RGB. Some development groups arbitrarily arranged in Figure 1 right hand side color grid layout - no reason it looks like this. If you spend some time to investigate the meaning of these connected colors within the color selection square, when moving your mouse on the screen, observe the color of the R, G, and B, you will be able to distinguish a mode. This mode is not obvious, however, maybe you have never guess a RGB value gives you the location you choose. In a relatively logical color selection scheme, the location of the color selector should have some contact with the selector.

Back to the very easy-to-use Windows General dialog, I remember to try to create my own color selection dialog box. There is no further understanding, so I started trying to create a two-dimensional grid to provide any RGB color. Soon, I realized that I am trying to solve a three-dimensional problem with two-dimensional tools. My simple solution is to provide a set of available colors, except for this simple method. In fact, RGB color space consists of standard Cartesian coordinates, with red, green, blue allocation color icons like x, y, and z values. The use of RGB color space specifies a color to select a point in three-dimensional space, and any component of this indicates the spacing of black (0,0,0) with three axes. The angle represented by the white (255, 255, 255) is the opposite of the color "cube".

So RGB is convenient, but not for human beings. Human is habit to think of color, satiety, and brightness in terms. In order to meet these needs, the Standard Color Selection dialog provides a selectable value, HSL style. This alternative arrangement is more meaningful for you and me, although it requires more work to do more work as it completes some complex mathematical calculations to change the HSL format value to a more generous RGB value. If you choose to drag the left, right or up and down and observe the HSL value, you will just see the style. That is, when you move from left to right, the color value increases from 0 to 240. When you move from the top to the bottom, the saturation value is reduced from 240 to 0. When you drag separate vertical slides from the top to the bottom, the brightness value is reduced from 240 to 0. Give these actual arrangements, you can relatively, becoming a proficiency transformation into a reasonable approximate corresponding HSL color value from the positions of the two points in the dialog. This situation does not apply RGB.

The tonal / saturation / value (HSV) color space is a HSL modification. The axis of the value is used to measure the brightness of the color, and your range cannot exceed the brightness of the saturation. In contrast, HSL allows you to move over the fullness of the brightness, through the crayon color, until white. HSV uses a value of a saturation of 0, providing all colors, these colors have the same red, green, and blue composition ingredients. (That is gray chromaticity). HSV is a color scheme in an instance application, and it is easy to explain. The components of the first HSV value, hue, equivalent to the angle in a circle. This circle contains the same color as shown in Figure 1, but arranged in a circular style (see Figure 2). This layout is given, the red color is equivalent to 0 degrees, the yellow is equivalent to 60 degrees, and so on. In the instance project, the special changes in the HSV are used to change the angle in the circle, so the value of color tones is allocated from 0 to 255-transformations to be completed inside the code. Figure 2 color circle

The saturation value is equivalent to the distance from the center. The color is in the circular boundary is a complete saturated center containing no saturated white. Figure 3 shows the range of green saturation values, as if drawn in the circle shown in Figure 2. Once again, I chose to feel more than the familiar RGB when I am arbitrary and only suitable for choosing colors. On authenticity, the instance can just use the floating point value between 0 and 1 to represent the saturation value.

Figure 3 saturation state

The value of the value includes the selected color brightness, which ranges from 255 (completely bright) to 0 (dark). Once again, important is not precise value - the change in this moment is just practical. Figure 4 shows green, its coordinate value changes from 255 to 0.

Figure 4 value

When you use the HSV color space in your work, you really have a colored cone. In the circle in Figure 2, the top of the cone is placed, and a line is down to the vertices of the cone from the circle, indicating black, providing the brightness range for each color. Figure 5 shows this conical three colors using bright axis: green, blue crystal, purple. A tone coordinate can represent any color, measuring the angle of surrounding circles, the coordinates of the saturation are the distance from the center distance, and the coordinates of the value are the distance from the vertices of the tape bottom.

转载请注明原文地址:https://www.9cbs.com/read-96946.html

New Post(0)