2016-08-25 68 views
1

我嘗試將多個過濾器應用於使用lumia圖像sdk的圖片,但我無法僅使用1個過濾器。當我爲Win 8.1製作的時候,我可以使用帶有過濾器的數組,但現在它不起作用。我如何解決它?將多個過濾器應用於圖片Lumia SDK UWP

代碼應用濾鏡:

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; 
} 

回答

0

當我做到了爲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(); 
}