Gdiplus::P mathGradientBrush in a MFC 应用程序不绘制
Gdiplus::PathGradientBrush in an MFC application doesn't draw
一个"简单"的直接代码,主要是从 MSDN 中的文章复制粘贴,不会产生任何输出。我添加了更多线条(使用普通 GDI 绘制)以确保坐标正确 - 这些线条工作正常。
代码正在更改STATIC
控件的背景,绘图在OnPaint
处理程序中执行。OnCtlColor
已扩充以返回此STATIC
控件的NULL_BRUSH
,因此框架不会完成绘制。
检查 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);
根据有关
WrapMode
枚举的 MSDN 文档(用作画笔构造函数的第三个默认参数),默认值WrapModeClamp
表示:
包装模式夹具
指定不进行切片。
一旦我将第三个参数添加到构造函数并指定了WrapModeTile
值,绘画就开始发生。
Gdiplus::PathGradientBrush brush(pts, 4, WrapModeTile);
或者使用画笔的TranslateTransform
正确偏移它,以便它绘制出预期的图案!在这种情况下,无需指定切片,因为它变得不必要。
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- Gdiplus::P mathGradientBrush in a MFC 应用程序不绘制
- 在MFC C++应用程序中在屏幕上绘制点的最快方法
- 打开不同的图像文件,并使用GDI 库在主应用程序窗口的背景上绘制它们
- Windows 8 现代 UI 应用程序和 DirectX.如何绘制文本
- 在第三方应用程序的窗口顶部绘制
- 绘制移动图标,它一直是最顶端的鼠标光标和工作的全屏应用程序
- 如何使用OpenGL在Windows上的同一应用程序中的两个单独的3D窗口中进行绘制
- 与测试平台应用程序相比,调试绘制Box2D非常大
- 为什么我的OpenGL 3.3应用程序没有绘制任何内容
- 在直接绘制全屏应用程序的顶部显示另一个应用程序
- QWebView应用程序在加载(使用日志)和绘制时崩溃
- 崩溃,在控制台应用程序上,试图绘制敌人,越界(遵循视频教程)
- 在编译的根 (CERN) 应用程序中将 TCanvas 绘制到屏幕上
- Qt5应用程序不会在Ubuntu上绘制任何窗口