如何在纯gdi(非gdi +)中为roundrect填充渐变 [英] how to fill gradient for roundrect in pure gdi (not gdi+)

查看:166
本文介绍了如何在纯gdi(非gdi +)中为roundrect填充渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅使用纯gdi. 想法或代码都欢迎.

just in pure gdi. thoughts or code are all welcome.

推荐答案

创建一个圆角的rect作为路径,选择该路径作为剪切路径,然后对同一矩形进行渐变填充. MFC中的代码如下所示:

Create a rounded rect as a path, select the path as the clipping path, then do a gradient fill of the same rectangle. Code with MFC would look like this:

int top = 10;
int left = 10;
int right = 200;
int bottom = 200;
int radius = 20;


pDC->BeginPath();
pDC->RoundRect(left, top, right, bottom, radius, radius);
pDC->EndPath();
pDC->SelectClipPath(RGN_COPY);

TRIVERTEX vertices[2];

vertices[0].x = left;
vertices[0].y = top;
vertices[0].Red = 0xffff;
vertices[0].Green = 0;
vertices[0].Blue = 0;
vertices[0].Alpha = 0xffff;

vertices[1].x = right;
vertices[1].y = bottom;
vertices[1].Red = 0;
vertices[1].Green = 0;
vertices[1].Blue = 0xffff;
vertices[1].Alpha = 0xffff;

GRADIENT_RECT r;
r.UpperLeft = 0;
r.LowerRight = 1;

pDC->GradientFill(vertices, 2, &r, 1, GRADIENT_FILL_RECT_V);

如果您不使用MFC,则pDC->x(...)将替换为x(your_DC, ...).

If you're not using MFC, the pDC->x(...) would be replaced with x(your_DC, ...).

这篇关于如何在纯gdi(非gdi +)中为roundrect填充渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆