应用几个过滤器来拍摄Lumia SDK UWP

本文关键字:Lumia SDK UWP 过滤器 几个 应用 | 更新日期: 2023-09-27 18:04:00

我尝试使用Lumia Imaging SDK对图片应用多个过滤器,但我只能使用一个过滤器。当我为Win 8.1制作它时,我可以使用一组过滤器,但现在不起作用了。我该如何解决?

应用过滤器的代码:

public async Task<bool> ApplyEffectAsync(StorageFile file)
{
    WriteableBitmap temp = new WriteableBitmap(1280, 720);
        temp = new WriteableBitmap(1280, 720);
        FileStream = await File.OpenAsync(FileAccessMode.Read);
        temp.SetSource(FileStream);
        OriginalPicture = temp;
        FileStream.Seek(0);
        original.Invalidate();
        ((IImageConsumer) Effect).Source = new RandomAccessStreamImageSource(FileStream);
        M_renderer = new WriteableBitmapRenderer((IImageProvider)Effect, original);
        FilteringPicture = await M_renderer.RenderAsync();
        filtering.Invalidate();
    return true;
}

应用几个过滤器来拍摄Lumia SDK UWP

当我为Win 8.1制作它时,我可以使用带有过滤器的数组,但现在它不起作用了。我该如何解决?

我不太明白你是如何在Win 8.1应用程序中做到这一点的,但是在UWP应用程序中,如果你想在图像上应用多个效果,你可以将最后渲染的效果源设置为另一个过滤器的新源。例如:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="500" />
        <RowDefinition Height="50" />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Image x:Name="originalimg" Grid.Column="0" />
        <SwapChainPanel x:Name="SwapChainPanelTarget" Grid.Column="1" />
        <Image x:Name="MutipleFilter" Grid.Column="2" />
    </Grid>
    <Button Content="Click Me" Click="Button_Click" Grid.Row="1" HorizontalAlignment="Center" />
</Grid>

背后的代码:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/test.jpg"));
    //show original image in the Image control
    IRandomAccessStream inputStream1 = await file.OpenReadAsync();
    BitmapImage bitmap = new BitmapImage();
    bitmap.SetSource(inputStream1);
    originalimg.Source = bitmap;
    //use the blureffect
    IRandomAccessStream inputStream = await file.OpenReadAsync();
    BlurEffect blureffect = new BlurEffect();
    inputStream.Seek(0);
    blureffect.Source = new Lumia.Imaging.RandomAccessStreamImageSource(inputStream);
    var render = new SwapChainPanelRenderer(blureffect, SwapChainPanelTarget);
    await render.RenderAsync();
    //multiple filters
    WriteableBitmap temp = new WriteableBitmap(1280, 720);
    LomoEffect lemoeffect = new LomoEffect();
    lemoeffect.Source = render.Source; //here, use the last rendered source as the new source of another effect
    var l_render = new WriteableBitmapRenderer(lemoeffect, temp);
    MutipleFilter.Source = await l_render.RenderAsync();
}