[Direct2D]Brushes Overview!笔刷~还是笔刷!

Brush Types Example

 

Win7中Direct2D的笔刷很丰富,效果也较以前买的版本漂亮了很多,在这个例题中,我们尝试绘制其中的几个笔刷:

 

Illustration of the visual effects from solid color brushes, linear gradient brushes, radial gradient brushes, and bitmap brushes

 

以上几个笔刷分别是纯色,渐进色笔刷和辐射型笔刷。

 

1)纯色笔刷

Illustration of a square painted with a solid color brush

 Illustration of a linear gradient brush with four stops along the axis

 

纯色笔刷主要绘制一个纯色,其中系统帮我们定义好了很多的颜色,以下是其中的一部分:

 

Illustration of predefined colors

hr = m_pRenderTarget->CreateSolidColorBrush(
    D2D1::ColorF(D2D1::ColorF::Black, 1.0f),
    &m_pBlackBrush
    );

 

 

ColorF()函数主要提供一个颜色值,这个函数使用起来传入的参数比较丰富,也比较方便,大致有以下几种:

ColorF(FLOAT, FLOAT, FLOAT, FLOAT)

ColorF(UINT32, FLOAT)

其中可以设定这个笔刷的半透明值,默认的是1.0f

 

 

2)渐变笔刷

Illustration of a square painted with a linear gradient brush of yellow and forest green

 

 

渐变笔刷主要是绘制一个区域线性的色彩变化,其中有一个很重要的概念就是D2D1_GRADIENT_STOP

D2D1_GRADIENT_STOP 是一个线性变化色盘,这个色斑中包含了渐变色的数据设置。

 

Illustration of a linear gradient brush with four stops along the axis

通过修改STOP就可以控制笔刷渐变色的过渡

 

另外一个重要概念就是D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES

 

他告诉我们,渐进式笔刷是沿着哪个方向进行色彩过渡的。根据我们填入的值,他会产生不同的直线结构:

 

Illustration of four different gradient axes across the same rectangle

Illustration of four different gradient axes across the same rectangle

3>辐射渐变笔刷

 

Illustration of a circle painted with a radial gradient brush

 

辐射型渐变笔刷也是通过D2D1_GRADIENT_STOP来控制颜色渐变的,作为辐射渐变笔刷是通过RadialGradientBrushProperties设定渐变位置:

 

Illustration of the same circle painted with radial gradient brushes with different origin offsets

Illustration of the same circle painted with radial gradient brushes with different origin offsets

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值