Ritu Tyagi
Ritu Tyagi

Reputation: 224

Add blur effect on image

i want blur effect on image on the potion which user tap.User can tap multiple times on image and when he taps the image potion which he taps get blur.

using (var blurfilters = new FilterEffect(source))
{
    var blur = new BlurFilter();

    blurfilters.Filters = new IFilter[] { blur };
    var target = new WriteableBitmap((int)img1.ActualWidth, (int)img1.ActualHeight);
    using (var renderer = new WriteableBitmapRenderer(blurfilters, target))
    {
        await renderer.RenderAsync();
        img1.Source = target;
    }
}

Upvotes: 9

Views: 7790

Answers (2)

Krunal Mevada
Krunal Mevada

Reputation: 1655

Try this One:

var blur = new BlurFilter(30);  

Edit :

To do the gaussian blur with WritableBitmapExtensions do the following (for some reason concolution doesn't edit the writableBitmap, so you have to assign it again to the same writableBitmap to see the result):

WriteableBitmap target = new WriteableBitmap((int)img1.ActualWidth, (int)img1.ActualHeight);
target = target.Convolute(WriteableBitmapExtensions.KernelGaussianBlur5x5);

or

target = target.Convolute(WriteableBitmapExtensions.KernelGaussianBlur3x3);

Upvotes: 0

Abhishek Dey
Abhishek Dey

Reputation: 1639

Try this:

http://www.blendrocks.com/code-blend/2015/1/29/implementing-image-blur-in-a-windows-universal-app

This worked for me for an universal app.

The effective code is:

private void OnDraw(CanvasControl sender, CanvasDrawEventArgs args)
{
    if (imageLoaded)
    {
        using (var session = args.DrawingSession)
        {
            session.Units = CanvasUnits.Pixels;

            double displayScaling = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0;

            double pixelWidth = sender.ActualWidth * displayScaling;

            var scalefactor = pixelWidth / image.Size.Width;

            scaleEffect.Source = this.image;
            scaleEffect.Scale = new Vector2()
            {
                X = (float)scalefactor,
                Y = (float)scalefactor
            };

            blurEffect.Source = scaleEffect;
            blurEffect.BlurAmount = Blur;

            session.DrawImage(blurEffect, 0.0f, 0.0f);
        }
    }
}

For Silverlight app try this one :

http://www.dotnetcurry.com/showarticle.aspx?ID=1033

Another good example if you wish Gaussian blur is:

WP8: Is there an easy way to scale and blur an BitmapImage for windows phone app?

Upvotes: 2

Related Questions