平滑圆形的窗角 [英] Smooth out rounded window corners
问题描述
HI
我已经使用Windows API调用CreateRoundRgn和SetWindowRgn创建了一个带有圆角边缘的窗口,但是圆角并不像用GDI +绘制的圆角矩形那样平滑.反正有什么方法可以使窗角变平滑?
I've created a window with rounded edges using the windows API calls CreateRoundRgn and SetWindowRgn however the rounded corners are not as smooth as say a rounded rectangle drawn with GDI+. Is there anyway to smooth out the window corners?
procedure TPBSDashboardPanel.DefineWindowRegion;
var
WindowRegion: HRGN;
begin
if Assigned(Parent) then
begin
WindowRegion := CreateRoundRectRgn(0, 0, Width, Height, 20, 20);
SetWindowRgn(Handle, WindowRegion, True);
end;
end;
推荐答案
也许可以使用具有alpha透明性的位图来模拟抗锯齿,此外还可以使用稍大的舍入区域以允许Windows进行命中测试.
Maybe use a bitmap with alpha transparency to simulate the anti-aliasing in addition to a slightly bigger rounded region for allowing Windows to do hit-testing.
这里的问题是Win32 GDI使用区域进行命中测试,因此在绘制区域中的每个点时,其整数单位都具有逻辑单位坐标,因此在进行命中测试时,可以知道该区域位于该区域之外或内部.
The problem here is that the Win32 GDI uses regions for hit-testing so when drawn every point in a region has integer logical unit coordinates, so that when hit-tested it can be known to be either outside or inside the region.
上帝保佑
PS:AFAIK无法定义窗口使用的实际区域,该区域会使窗口边框具有抗锯齿效果,并且Win32仅支持别名窗口.Windows 7中的WDM使边界模糊,但是我认为这是阴影而不是绘制得模糊的实际区域.
PS: AFAIK there is no way of defining the actual region used by a window which would make the windows borders to be rendered with anti-aliasing, and Win32 only supports aliased windows. The WDM in Windows 7 blurs the borders but I think this is the shadow and not the actual region which is drawn blurred.
这篇关于平滑圆形的窗角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!