LensBlurEffect Class

Applies blur to an image in a way similar to how out-of-focus areas are rendered by a lens, an effect also known as bokeh.

Inheritance Hierarchy

System..::..Object  Nokia.Graphics.Imaging..::..LensBlurEffect

Namespace: Nokia.Graphics.ImagingAssembly: Nokia.Graphics.Imaging (in Nokia.Graphics.Imaging.dll) Version: 255.255.255.255

Syntax

C#
public sealed class LensBlurEffect : IClosable, 
	IImageProvider, IImageConsumer, __ILensBlurEffectPublicNonVirtuals
Visual Basic
Public NotInheritable Class LensBlurEffect 
	Implements IClosable, IImageProvider, IImageConsumer, __ILensBlurEffectPublicNonVirtuals
Visual C++
public ref class LensBlurEffect sealed : IClosable, 
	IImageProvider, IImageConsumer, __ILensBlurEffectPublicNonVirtuals

Examples

C#

This sample takes CameraCaptureTask result photo and applies a LensBlur effect to it.

Universal apps:

private async void captureButton_Click(object sender, RoutedEventArgs e)
{
    await mediaCapture.StopPreviewAsync();
    
    var uri = new System.Uri("ms-appx:///Assets/mask.jpg");
    var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
    
    var stream = new InMemoryRandomAccessStream();
    await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
    stream.Seek(0);

    using (var source = new RandomAccessStreamImageSource(stream, ImageFormat.Jpeg))
    {
        using (var maskSource = new StorageFileImageSource((IStorageFile)file))
        using (var segmentation = new InteractiveForegroundSegmenter(source))
        using (var lensBlurEffect = new LensBlurEffect(source, new LensBlurPredefinedKernel(LensBlurPredefinedKernelShape.Circle, 20)))
        {
            segmentation.AnnotationsSource = maskSource;
            segmentation.ForegroundColor = Windows.UI.Color.FromArgb(255, 255, 255, 255);
            segmentation.BackgroundColor = Windows.UI.Color.FromArgb(255, 255, 238, 51);
            segmentation.Quality = 0.5;

            lensBlurEffect.KernelMap = segmentation;
            // Create a target where the filtered image will be rendered to
            var target = new WriteableBitmap((int)(Window.Current.Bounds.Width), (int)(Window.Current.Bounds.Height));

            // Create a new renderer which outputs WriteableBitmaps
            using (var renderer = new WriteableBitmapRenderer(lensBlurEffect, target))
            {
                // Render the image with the filter(s)
                await renderer.RenderAsync();

                // Set the output image to Image control as a source
                ImageControl.Source = target;
            }
        }
    }
}

Silverlight:

async void CaptureTask_Completed(object sender, PhotoResult e)
{
    const string imageFile = @"Assets\mask.jpg";
    var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

        using (var source = new StreamImageSource(e.ChosenPhoto))
        using (var maskSource = new StorageFileImageSource(file))
        using (var segmentation = new InteractiveForegroundSegmenter(source))
        using (var lensBlurEffect = new LensBlurEffect(source, new LensBlurPredefinedKernel(LensBlurPredefinedKernelShape.Circle, 20)))
        {
            segmentation.AnnotationsSource = maskSource; 
            segmentation.ForegroundColor = Color.FromArgb(255, 255, 255, 255); 
            segmentation.BackgroundColor = Color.FromArgb(255, 255, 238, 51); 
            segmentation.Quality = 0.5;
                    
            lensBlurEffect.KernelMap = segmentation;

            // Create a target where the filtered image will be rendered to
            var target = new WriteableBitmap((int)ImageControl.ActualWidth, (int)ImageControl.ActualHeight);

            // Create a new renderer which outputs WriteableBitmaps
            using (var renderer = new WriteableBitmapRenderer(lensBlurEffect, target))
            {
                // Render the image with the filter(s)
                await renderer.RenderAsync();

                // Set the output image to Image control as a source
                ImageControl.Source = target;
            }
        }
}
Visual Basic

Visual C++


Last updated 19 June 2014

Back to top

×