2017-10-11 24 views
0

article in MSDN”主要是一个复制粘贴的“简单”直接代码不会产生任何输出。我已经添加了几行(用普通的GDI绘图)以确保坐标正确 - 这些行工作得很好。MFC应用程序中的Gdiplus :: PathGradientBrush不绘制

代码正在更改STATIC控件的背景,并在OnPaint处理程序中执行绘图。 OnCtlColor增加了返回NULL_BRUSH这个STATIC控制,所以没有画架完成的框架。

检查GDI +对象和方法(在调试器中并通过日志记录)的状态显示一切正常。我很茫然,请帮助解决这个难题。

下面是相关的代码(除去错误处理和static_cast的我有\ W4):

CPaintDC dc(this); 
Graphics graphics(dc); 
CRect rc; 
GetDlgItem(IDC_STATIC_GS_COLOR)->GetWindowRect(&rc); // the STATIC to paint 
ScreenToClient(&rc); 

// GDI+ uses real numbers, not integers 
const Rect gdirc = Rect(rc.left, rc.top, rc.Width(), rc.Height()); 

// next 2 lines work just fine - painting a RED background 
const SolidBrush solidBrush((ARGB)Color::Red); 
graphics.FillRectangle(&solidBrush, gdirc); 

const PointF sz(rc.Width() - 1, rc.Height() - 1); 
PointF pts[] = {PointF(0, 0), PointF(sz.X, 0), PointF(sz.X, sz.Y), PointF(0, sz.Y)}; 
PathGradientBrush brush(pts, 4); 

Color colors[] = {Color(0, 0, 0), Color(255, 0, 0), Color(0, 255, 0), Color(0, 0, 255)}; 
int count = 4; 
brush.SetSurroundColors(colors, &count); 
brush.SetCenterColor(Color(128, 128, 128)); 

// !!!!! this doesn't fail, returns a status OK, and has NO EFFECT on the image :(
const auto status = graphics.FillRectangle(&brush, gdirc); 

// this draws a smaller inner GREEN rectangle, works as expected 
rc.DeflateRect(20, 20); 
dc.FillSolidRect(&rc, m_rgb); 

回答

0

根据MSDN documentationWrapMode枚举,作为第三,默认参数来刷的构造函数,默认值WrapModeClamp表示:

WrapModeClamp
指定不采取平铺地点。

一旦我将第三个参数添加到构造函数并指定了WrapModeTile值,绘画开始发生。

Gdiplus::PathGradientBrush brush(pts, 4, WrapModeTile); 

用画笔的TranslateTransform所以它描绘预期的模式,以适当弥补吧!在这种情况下,无需指定平铺,因为它变得没有必要。