GDIPlus的Pen的一个小Bug

来源:互联网 发布:老鼠夹编程乐高 编辑:程序博客网 时间:2024/05/21 05:42

首先是MSDN里面Pen的SetTransform Method的说明

Pen::SetTransform Method


The SetTransform method sets the world transformation of this Pen object.

Syntax

Status SetTransform(      

    const Matrix *matrix
);

Parameters

matrix
[in] Pointer to a Matrix object that specifies the world transformation.

Return Value

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

附MSDN上面的使用例子:

VOID Example_SetTransform(HDC hdc)
{
Graphics graphics(hdc);

Matrix matrix(20, 0, 0, 10, 0, 0); // scale

// Create a pen, and use it to draw a rectangle.
Pen pen(Color(255, 0, 0, 255), 2);
graphics.DrawRectangle(&pen, 10, 50, 150, 100);

// Scale the pen width by a factor of 20 in the horizontal
// direction and a factor of 10 in the vertical direction.
pen.SetTransform(&matrix);

// Draw a rectangle with the transformed pen.
graphics.DrawRectangle(&pen, 200, 50, 150, 100);
}

这里没有说明的是:
Pen pen(Color(255, 0, 0, 255), 2);
这里设置的线宽小于等于1.5时,则后面设置的坐标变换将不起作用,画出的线宽会变为1。
此外如果在设置坐标变换后,在某个方向的变换后线宽如果小于1,则也会失效,具体如下:
Pen pen(Color(255, 255, 0, 0), 2);
Matrix ctmBase(10, 0, 0, 0.5, 0, 100);
pen.SetTransform(&ctmBase);
GraphicsPath Path;
Path.AddLine(100, 300, 300, 300);
Path.AddLine(100, 300, 100, 600);
graphics.DrawPath(&pen, &Path);
你会发现两条线都为1线宽,只要把0.5增加一点,坐标变换就会正确作用了。