Skip to content

Instantly share code, notes, and snippets.

@foxxjnm
Created February 16, 2015 15:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save foxxjnm/e452f2aebc2f6a01874b to your computer and use it in GitHub Desktop.
Save foxxjnm/e452f2aebc2f6a01874b to your computer and use it in GitHub Desktop.
Xamarin.iOS Image Blur
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;
}
UIImage blurred = toBlur.Blur();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment