GDIPlus 中的阴影三角形

问题描述

我正在尝试使用 Gdiplus 对内插三角形的图像进行着色,但无法去除轮廓。这是使用CDC和Gdiplus的比较。

CDC 代码运行良好,如下所示:

void RenderTriangle(CDC* pDC,const CPoint* pts,COLORREF* cols)
{
    TRIVERTEX vertex[3];
    for (int i = 0; i < 3; i++) {
        vertex[i].x = pts[i].x;
        vertex[i].y = pts[i].y;
        vertex[i].Red = red[i];
        vertex[i].Green = green[i];
        vertex[i].Blue = blue[i];
        vertex[i].Alpha = 0x0000;
    }
    GRADIENT_TRIANGLE gTriangle;
    gTriangle.Vertex1 = 0;
    gTriangle.Vertex2 = 1;
    gTriangle.Vertex3 = 2;
    pDC->GradientFill(vertex,3,&gTriangle,1,GRADIENT_FILL_TRIANGLE);
}

输出

enter image description here

似乎没有 Gdiplus 的等价物,所以我使用的是 PathGradientBrush。我计算顶点颜色的平均值并将其用作中点颜色。代码如下:

void RenderTriangle(Graphics* graph,const PointF* pts,COLORREF* cols)
{
    int count = 3;
    PathGradientBrush pBrush(pts,3);
    Color colors[3];
    for (int i = 0; i < 3; i++) colors[i].SetFromCOLORREF(cols[i]);
    int r,g,b;
    r = g = b = 0;
    for (int i = 0; i < 3; i++) {
        r += colors[i].GetR();
        g += colors[i].GetG();
        b += colors[i].GetB();
    }
    pBrush.SetSurroundColors(colors,&count);
    pBrush.SetCenterColor(Color(r / 3,g / 3,b / 3));  //set center color
    graph->Fillpolygon(&pBrush,pts,3);
}

输出

enter image description here

我找不到其他方法来做到这一点,而且我无法摆脱轮廓。我尝试稍微“膨胀”三角形,以防它只是缺少轮廓,这确实减少了问题但并没有消除它。还有其他方法可以实现吗?

顺便说一句 - 我不能用其他不涉及三角形的解决方案来代替它。这不是图形问题,而是一个模拟,其中顶点处的值是输出

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)