Gdiplus::Pen 画虚线长度问题解释

画虚线的代码基本如下:

Gdiplus::Pen LinePen1Normal(Gdiplus::Color(255, 255, 255),2);
Gdiplus::REAL dashVals[2] = {1.5f,3.0f};
LinePen1Normal.SetDashPattern(dashVals,2);

很多人估计开始以为dashVals中的值指的是实线和空白的长度,但是如果真的是长度用int型不就好了,还要用个float,所以这两个值并不是长度,而是比值。

 

再看在msdn上面的解释:

This method will set the DashStyle enumeration for this Pen object to DashStyleCustom.

The elements in the dashArray array set the length of each dash and space in the dash pattern. The first element sets the length of a dash, the second element sets the length of a space, the third element sets the length of a dash, and so forth.

The length of each dash and space in the dash pattern is the product of the element value in the array and the width of the Pen object.

 

这句话的意思应该说的是线和空白的长度的算法是:线宽*dashVals[0]*dashVals[1],在这里就是2*1.5*3.0=9个像素

则实线的长度为:9*1.5/(1.5+3.0) = 3

空白的长度为:9*3/(1.5+3.0) = 6

 

显示效果如下图:

Gdiplus::Pen  画虚线长度问题解释

 

Gdiplus::Pen 画虚线长度问题解释

上一篇:由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置


下一篇:Skyeye中运行操作系统