UWP上的Gaussian Blur Effect刷不出来?
Gaussian Blur Effect on UWP can't brush?
我尝试按照 windows 开发人员 UWP 的教程进行操作,并达到了这一点
public sealed partial class MainPage : Page
{
private Compositor compositor = Window.Current.Compositor;
private SpriteVisual effectVisual;
private CompositionEffectBrush effectBrush;
public MainPage()
{
this.InitializeComponent();
}
private void BlurAmount_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
var blur_amount = (float)e.NewValue;
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
effectVisual = compositor.CreateSpriteVisual();
var graphicsEffect = new GaussianBlurEffect
{
BlurAmount = 100f,
BorderMode = EffectBorderMode.Hard,
Source = new CompositionEffectSourceParameter("Background")
};
var effectFactory = compositor.CreateEffectFactory(graphicsEffect);
effectBrush = effectFactory.CreateBrush();
var destinationBrush = compositor.CreateBackdropBrush();
effectBrush.SetSourceParameter("Background", destinationBrush);
effectVisual.Brush = effectBrush;
ElementCompositionPreview.SetElementChildVisual(theGrid, effectVisual);
}
}
这是我制作的UI,我想模糊根网格中心的网格,上面有图像背景
<Grid x:Name="Back">
<Grid.Background>
<ImageBrush ImageSource="Assets/1.png"/>
</Grid.Background>
<Grid x:Name="theGrid" VerticalAlignment="Center" HorizontalAlignment="Center"
Width="100" Height="100" ></Grid>
<Slider x:Name="BlurAmount" ValueChanged="BlurAmount_ValueChanged" Maximum="100" Minimum="0"/>
</Grid>
他的代码和我的一样,我复查了一千次,但我的模糊效果不适用于网格
我错过了什么吗?
我觉得有必要指定visual的大小,例如:
blurSprite.Size = new Vector2((float)theGrid.ActualWidth, (float)theGrid.ActualHeight);
我现在无法测试,但这应该会有所帮助。
我尝试按照 windows 开发人员 UWP 的教程进行操作,并达到了这一点
public sealed partial class MainPage : Page
{
private Compositor compositor = Window.Current.Compositor;
private SpriteVisual effectVisual;
private CompositionEffectBrush effectBrush;
public MainPage()
{
this.InitializeComponent();
}
private void BlurAmount_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
var blur_amount = (float)e.NewValue;
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
effectVisual = compositor.CreateSpriteVisual();
var graphicsEffect = new GaussianBlurEffect
{
BlurAmount = 100f,
BorderMode = EffectBorderMode.Hard,
Source = new CompositionEffectSourceParameter("Background")
};
var effectFactory = compositor.CreateEffectFactory(graphicsEffect);
effectBrush = effectFactory.CreateBrush();
var destinationBrush = compositor.CreateBackdropBrush();
effectBrush.SetSourceParameter("Background", destinationBrush);
effectVisual.Brush = effectBrush;
ElementCompositionPreview.SetElementChildVisual(theGrid, effectVisual);
}
}
这是我制作的UI,我想模糊根网格中心的网格,上面有图像背景
<Grid x:Name="Back">
<Grid.Background>
<ImageBrush ImageSource="Assets/1.png"/>
</Grid.Background>
<Grid x:Name="theGrid" VerticalAlignment="Center" HorizontalAlignment="Center"
Width="100" Height="100" ></Grid>
<Slider x:Name="BlurAmount" ValueChanged="BlurAmount_ValueChanged" Maximum="100" Minimum="0"/>
</Grid>
他的代码和我的一样,我复查了一千次,但我的模糊效果不适用于网格 我错过了什么吗?
我觉得有必要指定visual的大小,例如:
blurSprite.Size = new Vector2((float)theGrid.ActualWidth, (float)theGrid.ActualHeight);
我现在无法测试,但这应该会有所帮助。