GDI +线性渐变奇怪的行为

时间:2017-03-10 15:06:39

标签: c++ drawing gdi+ linear-gradients brush

我需要创建一个线性渐变画笔来用GDI +绘制表面。在输入上,我收到以下参数:

Viewport rect:   x = 0, y = 0, width = 744.09448819f, height = 1052.3622047f
Fill rect:       x = 13.040037f, y = 17.478735f, width = 721.3703f, height = 1009.1535f
Gradient start:  x = 384.8, y = 611.46
Gradient stop:   x = 378.93, y = 474.96
Start color:     a = 255, r = 179, g = 221, b = 253 (between 0 and 255)
End color:       a = 255, r = 51, g = 102, b = 152  (between 0 and 255)
Matrix to apply: a = 7.7430985, b = 0, c = 0, d = 7.2926249, e = -2439.6639, f = -3446.2263
Wrap mode:       clamp

这些值是从SVG文件中提取的。当我用浏览器打开它时,我得到以下结果: https://drive.google.com/open?id=0B7C-RwCTA9qaNnFsaGJpenlseGc

现在我尝试使用GDI +绘制完全相同的渐变。我使用Embarcadero RAD Studio c ++ builder来做到这一点。我写了以下代码:

void DrawGradient()
{
    std::auto_ptr<TBitmap> pBitmap(new TBitmap());
    pBitmap->Width  = 744.09448819f;
    pBitmap->Height = 1052.3622047f;
    pBitmap->Canvas->Brush->Color = clWhite;
    pBitmap->Canvas->FillRect(TRect(0, 0, pBitmap->Width, pBitmap->Height));

    Gdiplus::Graphics graphics(pBitmap->Canvas->Handle);

    Gdiplus::LinearGradientBrush brush(
                                       Gdiplus::PointF(384.8, 611.46),
                                       Gdiplus::PointF(378.93, 474.96),
                                       Gdiplus::Color(255, 179, 221, 253),
                                       Gdiplus::Color(255, 51, 102, 152)
                                      );

    Gdiplus::Matrix matrix(7.7430985, 0, 0, 7.2926249, -2439.6639, -3446.2263);
    brush.SetTransform(&matrix);

    graphics.FillRectangle(&brush, 13.040037f, 17.478735f, 721.3703f, 1009.1535f);

    pBitmap->SaveToFile(L"test.bmp");
}

但是我得到了这个结果: https://drive.google.com/open?id=0B7C-RwCTA9qaU1BhSTJxay16Z00

暂且不考虑钳位问题,我知道GDI +没有提供简单的解决方案(例如将Gdiplus :: WrapModeClamp放在SetWrapMode()函数中,对于用户来说这很容易),结果图至少应该接近预期的结果,或者我错了?

有人可以向我解释为什么我会得到如此不同的结果?

注意我已经调整了所有参数,我只获得了相同错误结果的几种变体

注意我在上面提到的原始SVG可以在这里获得: https://drive.google.com/open?id=0B7C-RwCTA9qaYkNRQ3lJNC1fNmM

此致

0 个答案:

没有答案