"Programming WPF" translation 7th Chapter 3. Brushes and Pens

Source: Internet
Author: User
Tags color representation range require sca

To draw a graphic on the screen, WPF needs to know what color you want to fill the graphic and how to draw its borders. WPF provides a number of brush types that support various drawing styles. The pen class adds these brushes to provide the thickness and appearance of the border.

In this chapter, we will look at the various types of brushes and pen classes. However, since all the brushes and pens are ultimately about which color to use and how to combine them together, we must first look at how the wink is expressed.

7.3.1 Color

WPF uses a color structure in the System.Windows.Media namespace to represent a colour. Note that if you have previously worked in Windows Forms, ASP. NET or gdi+,color institutions are different from those used by those technologies-they use the color structure of the System.Drawing namespace. WPF introduces this new color structure because it works with color values in floating-point form-support for higher color accuracy, and better elasticity.

The color structure uses four digits, or a channel, to represent a color. These channels are red, green, blue, and Alpha. Red, green, blue channel is the traditional way of representing color in computer graphics. (This is because the color screen works by mixing the three basic colors together.) A value of 0 indicates that the color portion does not exist at all, and that all three channels are 0 corresponding to black. The alpha channel represents the level of color opacity. Color can be opaque, completely opaque, and any value between these two limits. WPF's compositing engine fully supports transparency, so any graphic can be drawn to a transparent level. A value of 0 is used to indicate full transparency.

Windows is a traditional use of 24-bit color information, 8-bit color per channel to represent "True Color", and 32-bit true color with transparency. This is just enough about the average level of the computer screen. The color and brightness range of conventional computer performance is that 24-bit color is always sufficient for most purposes. However, for many graphical applications, this is not enough. For example, a movie, which provides a wider range of brightness than a computer screen, and 24-bit colors are simply not enough to work with graphics as an output medium, nor is it suitable for many medical imaging applications. Even for computers and video images, 24-bit colors can cause problems. If images require many stages of processing, these increase the limit of 24-bit raw materials.

WPF therefore supports a fairly high level of detail in its color representation. Each color channel uses 16-bit instead of 8-bit. This color structure still supports the use of 8-bit channels where needed, since most image software relies on such representations. Color exposes these 8-bit channels through a, R, G, and B properties that accept values between 0 and 255. This more advanced definition notation is also valid through SCA, ScR, ScG, SCB properties, which represent single-precision floating-point values in the range of 0 to 1.

The "Sc" in the ScA, ScR, SCG, and SCB properties involves the fact that they support the standard "Extended RGB colour Spacescrgb", where the color space is defined in the IEC61966-2-2 specification. "SC" is the abbreviation for "scene" because it is usually a scenereferred color space. This means that the color value of the ScRGB space represents the color of the original image. This is different from how computer images are usually stored. Traditionally, we have used the outputreferred color space, and the color value does not need to be mapped there before it is displayed on the target device.

The use of outputreferred color space can work effectively as long as they exactly set the target of the input device. However, the scenereferred color space protects all available information when capturing or generating images. For higher-precision color representations, the scenereferred model is therefore clearer. Even if they work a little less efficiently.

There is also a color class that provides a standard set of named colors, including all the old favorites, such as Papaywhip, Burlywood, Lightgoldenrodyellow, and Brown.

7.3.2 SolidColorBrush

SolidColorBrush is the simplest brush. It paints the entire area with a color. It has only one attribute, Color. Note that this color allows for transparency, although solid is used in the word.

We have seen extensive use of SolidColorBrush, even though we have not provided a name to cover it. This is because WPF creates this type of brush once you specify the name of the color in the tag. If you

Most of the work in the tag, you will rarely need to point out that you need a SolidColorBrush, because you will get a default value. (usually you will specify it in full terms, the only reason is that you want to use the Brush property data binding). Consider the following example:

<Rectangle Fill=”Yellow” Width=”100” Height=”20” />

The XAML compiler recognizes yellow as a standard named color in the color class, which provides a suitable solidcolorbrush. (See Appendix A For more information on XAML mapping strings to property values). This does not require creating a brush because there is a brushes class that provides a set of brushes for each named color in colors.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.