如何在圆角矩形上添加阴影 [英] How to add shadow to a round rectangle
本文介绍了如何在圆角矩形上添加阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用vc ++/mfc绘制一个圆形矩形(OnPaint()),有人可以帮我在阴影的右边缘和下边缘添加阴影吗?
I am using vc++/mfc to draw a round rectangle (OnPaint()),Can anyone help me to add shadow to a rectangle on right and bottom edges ?
推荐答案
圆角矩形"是矛盾词.也许你的是四舍五入的.阴影的简单模型是:-).
阴影的简单模型是根据光源移动的,呈凸起形状的稍微模糊的半透明图像,而不是边缘.它不太现实,但却被普遍接受.
我只找到了以下代码: GDI +中的模糊DropShadows [
"Round rectangle" is oxymoron. Perhaps yours is rounded. A simple model of a shadow is :-).
A simple model of a shadow is a slightly fuzzy semi-transparent image of the elevated shape, not the edges, shifted according to light source. It is not quite realistic but is commonly accepted.
I only found this code: Fuzzy DropShadows in GDI+[^]. Sorry, this is C# and .NET, but as the algorithm is based on GDI+, you can easily translate it; you only need the algorithm.
—SA
我想您是在不使用GDI的情况下完成的.您的代码可能如下所示.
I guess you have done it without using GDI. your code may look somewhat like below.
.....
dc.SelectObject( &somebrush );
dc.RoundRect( x1, y1, x2, y2, p1, p2 );
......
现在要带来阴影效果,请更改代码,如下所示.
now to bring the shadow effect change the code as below.
......
// New codes Starts here
CBrush shdwBrsh;
shdwBrsh.CreateSolidBrush( GetSysColor( COLOR_BTNSHADOW ));
dc.SelectObject( &shdwBrsh );
dc.RoundRect( x1+5, y1+5, x2+5, y2+5, p1, p2 );
// New codes Ends here
dc.SelectObject( &somebrush );
dc.RoundRect( x1, y1, x2, y2, p1, p2 );
............
这篇关于如何在圆角矩形上添加阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文