Win2D阴影看起来参差不齐

时间:2019-03-12 01:55:46

标签: c# xaml uwp win2d

我正在尝试使用Win2D软件包在UWP应用中创建投影。这是文档(https://docs.microsoft.com/en-us/windows/uwp/composition/using-the-visual-layer-with-xaml)的逐行显示。为什么阴影看起来像这样而不是光滑:

enter image description here

Xaml:

<Grid >
  <Border x:Name="ShadowHost" />
  <Border Width="562" Height="250" Background="White" />
</Grid>

C#:

private void OnLoaded(object sender, RoutedEventArgs e)
{
    Compositor shadowCompositor;
    Visual hostVisual;

    hostVisual = ElementCompositionPreview.GetElementVisual(this.ShadowHost);
    shadowCompositor = hostVisual.Compositor;

    var dropShadow = shadowCompositor.CreateDropShadow();
    dropShadow.Offset = new Vector3(0, 16, 0);
    dropShadow.BlurRadius = 80.0f;
    dropShadow.Color = Color.FromArgb(128, 0, 0, 0);

    var spriteVisual = shadowCompositor.CreateSpriteVisual();
    spriteVisual.Size = new Vector2(562f, 250f);
    spriteVisual.Shadow = dropShadow;

    ElementCompositionPreview.SetElementChildVisual(this.ShadowHost, spriteVisual);

    var bindSizeAnimation = shadowCompositor.CreateExpressionAnimation("hostVisual.Size");
    bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual);
    spriteVisual.StartAnimation("Size", bindSizeAnimation);
    }

1 个答案:

答案 0 :(得分:0)

使用最新的SDK 17763时,相同的代码将创建以下输出: enter image description here看起来像一个平滑的输出。您可能需要检查目标SDK版本或像Johnny所述的驱动程序/图形卡。