protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is IImageProvider) { var sourceParam = (IImageProvider)e.Parameter; ImageElement.Source = effect = new CartoonEffect(sourceParam); } }
async Task <Uri> Cartoon() { using (var source = new StorageFileImageSource(imageStorageFile)) { var inf = await source.GetInfoAsync(); using (var sharpnessEffect = new CartoonEffect(source) { DistinctEdges = false }) { LastEffect = sharpnessEffect; return(await SaveToImage()); } } }
private async Task <bool> ApplyFilterAsync(StorageFile file) { // Open a stream for the selected file. IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); string errorMessage = null; try { // Show thumbnail of original image. _thumbnailImageBitmap.SetSource(fileStream); OriginalImage.Source = _thumbnailImageBitmap; // Rewind stream to start. fileStream.Seek(0); // A cartoon effect is initialized with selected image stream as source. var imageStream = new RandomAccessStreamImageSource(fileStream); _cartoonEffect = new CartoonEffect(imageStream); // Render the image to a WriteableBitmap. var renderer = new WriteableBitmapRenderer(_cartoonEffect, _cartoonImageBitmap); _cartoonImageBitmap = await renderer.RenderAsync(); _cartoonImageBitmap.Invalidate(); // Set the rendered image as source for the cartoon image control. CartoonImage.Source = _cartoonImageBitmap; } catch (Exception exception) { errorMessage = exception.Message; } if (!string.IsNullOrEmpty(errorMessage)) { var dialog = new MessageDialog(errorMessage); await dialog.ShowAsync(); return(false); } return(true); }