Created
February 16, 2015 15:58
-
-
Save foxxjnm/e452f2aebc2f6a01874b to your computer and use it in GitHub Desktop.
Xamarin.iOS Image Blur
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static UIImage Blur(this UIImage image, float blurRadius = 25f) | |
{ | |
if (image != null) | |
{ | |
// Create a new blurred image. | |
var imageToBlur = new CIImage (image); | |
var blur = new CIGaussianBlur (); | |
blur.Image = imageToBlur; | |
blur.Radius = blurRadius; | |
var blurImage = blur.OutputImage; | |
var context = CIContext.FromOptions (new CIContextOptions { UseSoftwareRenderer = false }); | |
var cgImage = context.CreateCGImage (blurImage, new RectangleF (new PointF (0, 0), image.Size)); | |
var newImage = UIImage.FromImage (cgImage); | |
// Clean up | |
imageToBlur.Dispose (); | |
context.Dispose (); | |
blur.Dispose (); | |
blurImage.Dispose (); | |
cgImage.Dispose (); | |
return newImage; | |
} | |
return null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIImage blurred = toBlur.Blur(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment