Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.