我正在尝试有一个Visual
有圆角。这是我的代码:
auto clip = compositor->CreateGeometricClip();
auto roundedRectangle = compositor->CreateRoundedRectangleGeometry();
roundedRectangle->Size = Windows::Foundation::Numerics::float2(width, height);
roundedRectangle->CornerRadius = Windows::Foundation::Numerics::float2(10, 10);
clip->Geometry = roundedRectangle;
visual->Clip = clip;
这可行,但会在视觉效果的所有 4 个角上创建圆角。是否可以使用Composition
API 可以实现我的目标吗?作为参考,这是我想要的最终结果。
而不是我现在拥有的
您可以尝试使用Offset https://learn.microsoft.com/en-us/uwp/api/windows.ui.composition.compositionroundedrectanglegeometry.offset?view=winrt-19041财产和CornerRadius
的财产CompositionRoundedRectangleGeometry
实例以获得您想要的效果。这Visual.Clip
属性指定视觉对象的剪切区域。渲染视觉对象时,仅显示位于剪切区域内的视觉部分,而延伸到剪切区域之外的任何内容都会被剪切。因此,我们可以通过调整圆角矩形的大小来切掉圆角矩形右侧的一小部分visual
以及的大小和偏移量clip
.
请检查以下代码作为示例:
auto clip = _compositor->CreateGeometricClip();
auto roundedRectangle = _compositor->CreateRoundedRectangleGeometry();
roundedRectangle->Size = float2(100, 100);
//roundedRectangle->CornerRadius = float2(20, 20);
roundedRectangle->Offset = float2(20, 0);
clip->Geometry = roundedRectangle;
//auto visual = _compositor->CreateSpriteVisual();
//visual->Brush = _compositor->CreateColorBrush(ColorHelper::FromArgb(0xFF, 0xFF, 0x11, 0xFF));
visual->Size = float2(100+20, 100);
roundedRectangle->Size = visual->Size;
visual->Clip = clip;
关键是让大小visual
大小相同clip
,并设置一个值Offset
的财产clip
使圆角矩形的右侧部分超过visual
。第一个参数为Offset
属性表示左右之间的空间clip
and visual
。我设置的值为Offset
as float2(20, 0)
让圆角矩形的右边部分超过visual
。您可以调整值Offset
财产根据您的需要。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)