Skip to content

Instantly share code, notes, and snippets.

@BrunoVT1992
Last active April 26, 2016 07:39
Show Gist options
  • Save BrunoVT1992/27b64bca4c024d6ad6885a6e5c7a2377 to your computer and use it in GitHub Desktop.
Save BrunoVT1992/27b64bca4c024d6ad6885a6e5c7a2377 to your computer and use it in GitHub Desktop.
Bitmap blur util for Xamarin Android
using Android.App;
using Android.Support.V8.Renderscript;
namespace Droid
{
public static class BitmapUtil
{
public static Bitmap Blur(Bitmap originalBitmap)
{
// Create the Renderscript instance that will do the work.
RenderScript rs = RenderScript.Create(Application.Context);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, (int)Renderscripts.AllocationUsage.Script);
Allocation output = Allocation.CreateTyped(rs, input.Type);
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs));
script.SetInput(input);
// Set the blur radius
script.SetRadius(25);
// Start the ScriptIntrinisicBlur
script.ForEach(output);
// Copy the output to the blurred bitmap
output.CopyTo(originalBitmap);
return originalBitmap;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment