Windows Phone development (31): Brush turn: http://blog.csdn.net/tcjiaan/article/details/7460226

Source: Internet
Author: User

What is painter? Actually, the painter is used for graffiti. Actually, I did not lie to you. As for whether you believe it or not, I believe it.
This article describes several typical painter models to help you understand that the painter is used for graffiti.

1. Solid color paint brush solidcolorbrush.

This guy is "pure", of course it is not pure, it is indeed pure, pure to only use one color, so it is called "monochrome paint brush ".
Let's take a look at this example. We will draw a rectangle (put it in a canvas) and then dress it up with this pure guy.

[HTML]View plaincopyprint?

  1. <Rectangle canvas. Left = "5" canvas. Top = "130" width = "85" Height = "75">
  2. <Rectangle. Fill>
  3. <Solidcolorbrush color = "white"/>
  4. </Rectangle. Fill>
  5. </Rectangle>

 

Because of the built-in converter, Microsoft has always been concerned about the health of developers, So ms is not willing to be too tired when we write code, so the above content can be abbreviated.

[HTML]View plaincopyprint?

  1. <Rectangle canvas. Left = "110" canvas. Top = "156"
  2. Width = "120" Height = "120" fill = "blue"/>

 

The effects of these two codes are the same. Obviously, you will prefer the latter because it is more concise than N.

Next, let's take a look at the representation of the color attribute.
1. the name, such as blue, does not need to be translated;
2. RGB, such as # cccccc. If you have worked on Webpage Design and wrote CSS Styles, you know;
3. argb, such as #0 cbbbbbbbb, is actually adding a value in front, between 0 and 1, transparency.
It can be said that you can write out countless colors after remembering the above three points.

 

 

 

Ii. Gradient paint brush.

If you have used drawing software like Photoshop, or you have used GDI programming, of course you have used WPF better.
Gradient color, which can be understood as follows: consists of N colors, which have their own distribution and there is a transition between colors of each segment.
Let's take a look at two gradient forms: Linear and radial.
(1) linear gradient
Let's take a look at the figure below. I believe that no text is more intuitive than the image. I believe you will know what a linear gradient is.

Okay. How is the above effect achieved? Lineargradientbrush is used. Take a look at the XAML code.

[HTML]View plaincopyprint?

  1. <Rectangle canvas. Top = "312" canvas. Left = "40" width = "278" Height = "95">
  2. <Rectangle. Fill>
  3. <Lineargradientbrush startpoint = "0, 0" endpoint = "1, 1">
  4. <Gradientstop color = "yellow" offset = "0"/>
  5. <Gradientstop color = "green" offset = "0.5"/>
  6. <Gradientstop color = "orange" offset = "1"/>
  7. </Lineargradientbrush>
  8. </Rectangle. Fill>
  9. </Rectangle>

Here, we need to pay attention to the following points:
1. startpoint: the starting point of the linear gradient. Since it is linear, it must start and end. The values of X and Y are between 0 and 1;
2. endpoint: End Point. Similarly, the value range is between 0 and 1.
3. Point 0 to the upper left corner, and point 1 to the lower right corner.
Each lineargradientbrush can contain N gradientstop, indicating the end point of each color, as shown in.

If you do not understand it very well, the best way is to practice more.

 

[HTML]View plaincopyprint?

  1. <Ellipse canvas. Top = "465" canvas. Left = "40" width = "150" Height = "120">
  2. <Ellipse. Fill>
  3. <Lineargradientbrush startpoint = "0.5, 0" endpoint = "0.5, 1">
  4. <Gradientstop color = "# ff8e8ee8"/>
  5. <Gradientstop color = "# ffdbbc55" offset = "0.6"/>
  6. <Gradientstop color = "# ff61ddf5" offset = "0.99"/>
  7. </Lineargradientbrush>
  8. </Ellipse. Fill>
  9. </Ellipse>

The Running Effect of the preceding two examples is shown in.

 

 

(2) radial gradient
The name is hard to understand. Let's take a look at the graph and write the text.

How is it beautiful? Let's look at the implemented XAML code.

[HTML]View plaincopyprint?

  1. <Rectangle canvas. Left = "242" canvas. Top = "465" width = "150" Height = "150">
  2. <Rectangle. Fill>
  3. <Radialgradientbrush center = "0.5, 0.5" radiusx = "0.5" radiusy = "0.5">
  4. <Gradientstop color = "green" offset = "0.2"/>
  5. <Gradientstop color = "lightblue" offset = "0.7"/>
  6. <Gradientstop color = "yellow" offset = "1"/>
  7. </Radialgradientbrush>
  8. </Rectangle. Fill>
  9. </Rectangle>

Look, there are several attributes that are more eye-catching.
1. Center, Center. You can see that the radial gradient is like a circle with a center point and a radius. Similarly, the value range is [0, 1].
2. radiusx and radiusy. Similarly, the radius ranges from 0 to 1, and the radius of the horizontal and vertical axes.
We can find that these values are relative logical values, which are more flexible than absolute positions.

 

 

3. videobrush.

 

This should be used with mediaelement, which has been introduced in the previous article.

 

 

 

4. Image painter imagebrush.

 

If you think that the Front color is not good enough, take a look at it and fill it with images.

The implemented XAML is as follows.

[HTML]View plaincopyprint?

  1. <Ellipse canvas. Left = "40" canvas. Top = "445" width = "398" Height = "248">
  2. <Ellipse. Fill>
  3. <Imagebrush imagesource = "test.jpg"/>
  4. </Ellipse. Fill>
  5. </Ellipse>

 

This is simple. The imagesource attribute points to an image, which is similar to the image control.

Related Article

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.