导航:  GdiPlus Classes > GdiPlus Classes > CGpBrush Class > CGpLinearGradientBrush Class > LinearGradientBrush Object >

GetInterpolationColorCount

上一页返回章节概述下一页

描述

 

获取当前为线性渐变画笔插入的颜色数目.

 

C++ Syntax

 

INT GetInterpolationColorCount() const;

 

FreeBASIC 语法

 

FUNCTION GetInterpolationColorCount () AS INT_

 

参数

 

该方法没有参数.

 

返回值

 

此方法返回要为此线性渐变刷进行插值的颜色数.如果没有颜色,已经用SetInterpolationColors,或者无效的位置传给了SetInterpolationColors,然后GetInterpolationColorCount返回0.

 

备注

 

一个简单的线性渐变画笔有两种颜色:起始边界处的颜色和结束边界处的颜色.当你用这种画笔作画时,颜色会从起始颜色到结束颜色,从起始边界到结束边界开始逐渐改变.你可以用SetInterpolationColors方法指定一个颜色数组和其相应的混合位置插值到这种线性渐变画笔创建一个更复杂的梯度.

 

你可以获得颜色和混合位置目前设置为通过调用它的GetInterpolationColors方法线性渐变画笔.在你打电话的GetInterpolationColors方法,你必须分配缓冲:一把颜色数组和一个持有的混合位置数组.你可以打电话给GetInterpolationColorCount方法来确定所需的缓冲区大小.的颜色缓冲区的大小是GetInterpolationColorCount乘以sizeof(Color)返回值.共混物的位置,缓冲区的大小是GetInterpolationColorCount乘以sizeof( REAL)价值.

 

引用文件

 

CGpBrush.inc (include CGdiPlus.inc)

 

示例

 

' ========================================================================================

' The following example sets the colors that are interpolated for this linear gradient

' brush to red, blue, and green and sets the blend positions to 0, 0.3, and 1. The code

' calls the LinearGradientBrush::GetInterpolationColorCount method of a LinearGradientBrush

' object to obtain the number of colors currently set to be interpolated for the brush.

' Next, the code gets the colors and their positions. Then, the code fills a small

' rectangle with each color.

' ========================================================================================

SUB Example_GetInterpolationColors (BYVAL hdc AS HDC)

 

  ' // Create a graphics object from the window device context

  DIM graphics AS CGpGraphics = hdc

  ' // Get the DPI scaling ratio

  DIM rxRatio AS SINGLE = graphics.GetDpiX / 96

  DIM ryRatio AS SINGLE = graphics.GetDpiY / 96

  ' // Set the scale transform

  graphics.ScaleTransform(rxRatio, ryRatio)

 

  ' // Create a linear gradient brush, and set the colors to be interpolated.

  DIM colors(0 TO 2) AS ARGB = {GDIP_ARGB(255, 255, 0, 0), GDIP_ARGB(255, 0, 0, 255), GDIP_ARGB(255, 0, 255, 0)}

  DIM positions(0 TO 2) AS SINGLE = {0.0, 0.3, 1.0}

 

  DIM pt1 AS GpPoint = GDIP_POINT(0, 0)

  DIM pt2 AS GpPoint = GDIP_POINT(100, 0)

 

  DIM linGrBrush AS CGpLinearGradientBrush = CGpLinearGradientBrush(@pt1, @pt2, GDIP_ARGB(255, 0, 0, 0), GDIP_ARGB(255, 255, 255, 255))

  linGrBrush.SetInterpolationColors(@colors(0), @positions(0), 3)

 

  ' // Obtain information about the linear gradient brush.

  ' // How many colors have been specified to be interpolated for this brush?

  DIM colorCount AS LONG = linGrBrush.GetInterpolationColorCount

 

  ' // Allocate a buffer large enough to hold the set of colors.

  DIM rgcolors(0 TO colorCount - 1) AS ARGB

 

  ' // Allocate a buffer to hold the relative positions of the colors.

  DIM rgPositions(0 TO colorCount - 1) AS SINGLE

 

  ' // Get the colors and their relative positions.

  linGrBrush.GetInterpolationColors(@rgcolors(0), @rgPositions(0), colorCount)

 

  ' // Fill a small rectangle with each of the colors.

  DIM pSolidBrush AS CGpSolidBrush PTR

  FOR j AS LONG = 0 TO colorCount - 1

     pSolidBrush = NEW CGpSolidBrush(rgcolors(j))

     graphics.FillRectangle(pSolidBrush, 15 * j, 0, 10, 10)

     Delete pSolidBrush

  NEXT

 

END SUB

' ========================================================================================