Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
    }
}
like image 866
Ritu Tyagi Avatar asked May 04 '15 07:05

Ritu Tyagi


1 Answers

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?

like image 118
Abhishek Dey Avatar answered Oct 20 '22 01:10

Abhishek Dey