public Bitmap Transform(Bitmap source) { // Load a clean bitmap and work from that. var originalBitmap = source; // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap = null; blurredBitmap = Bitmap.CreateBitmap(originalBitmap); // Create the Renderscript instance that will do the work. var rs = RenderScript.Create(Context); // Allocate memory for Renderscript to work with var input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); var output = Allocation.CreateTyped(rs, input.Type); // Load up an instance of the specific script that we want to use. var script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); script.SetInput(input); // Set the blur radius script.SetRadius(Radius); // Start the ScriptIntrinisicBlur script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBitmap); source.Recycle(); return(blurredBitmap); }
public static Drawable CreateBlurredImageFromBitmap(Bitmap bm, Context context, int size) { var rs = RenderScript.Create(context); var options = new BitmapFactory.Options { InSampleSize = size }; byte[] imageInBytes; using (var stream = new MemoryStream()) { bm.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); imageInBytes = stream.ToArray(); } var blurred = BitmapFactory.DecodeByteArray(imageInBytes, 0, imageInBytes.Length); var input = Allocation.CreateFromBitmap(rs, blurred); var output = Allocation.CreateTyped(rs, input.Type); var script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); script.SetRadius(8f); script.SetInput(input); script.ForEach(output); output.CopyTo(blurred); return(new BitmapDrawable(context.Resources, blurred)); }
public override Bitmap Operations(Bitmap source, Bitmap result) { Bitmap originalBitmap = source; Bitmap blurredBitmap = null; blurredBitmap = Bitmap.CreateBitmap(originalBitmap); var rs = RenderScript.Create(mContext); var input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); var output = Allocation.CreateTyped(rs, input.Type); var script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); script.SetInput(input); script.SetRadius(mRadius); script.ForEach(output); output.CopyTo(blurredBitmap); source.Recycle(); return(blurredBitmap); }
private Bitmap CreateBlurredImage(Bitmap originalBitmap, int radius) { // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap; blurredBitmap = Bitmap.CreateBitmap(originalBitmap); // Create the Renderscript instance that will do the work. RenderScript rs = RenderScript.Create(Context); // Allocate memory for Renderscript to work with Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, 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, Android.Renderscripts.Element.U8_4(rs)); script.SetInput(input); // Set the blur radius script.SetRadius(radius); // Start Renderscript working. script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBitmap); return(blurredBitmap); }
public static Bitmap RsBlur(Context context, Bitmap source, int radius) { Bitmap inputBmp = source; //(1) RenderScript renderScript = RenderScript.Create(context); // Allocate memory for Renderscript to work with //(2) Allocation input = Allocation.CreateFromBitmap(renderScript, inputBmp); Allocation output = Allocation.CreateTyped(renderScript, input.Type); //(3) // Load up an instance of the specific script that we want to use. ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur .Create(renderScript, Element.U8_4(renderScript)); //(4) scriptIntrinsicBlur.SetInput(input); //(5) // Set the blur radius scriptIntrinsicBlur.SetRadius(radius); //(6) // Start the ScriptIntrinisicBlur scriptIntrinsicBlur.ForEach(output); //(7) // Copy the output to the blurred bitmap output.CopyTo(inputBmp); //(8) renderScript.Destroy(); return(inputBmp); }
public Bitmap BlurImage(Bitmap image) { if (image == null) return null; image = RGB565toARGB888(image); if (!configured) { input = Allocation.CreateFromBitmap(rs, image); output = Allocation.CreateTyped(rs, input.Type); script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); script.SetRadius(BLUR_RADIUS); configured = true; } else { input.CopyFrom(image); } script.SetInput(input); script.ForEach(output); output.CopyTo(image); return image; }
private Bitmap FastBlur(Bitmap sentBitmap) { try { if (null == sentBitmap) { return(null); } Bitmap outputBitmap = Bitmap.CreateBitmap(sentBitmap); RenderScript renderScript = RenderScript.Create(ActivityContext); Allocation tmpIn = Allocation.CreateFromBitmap(renderScript, sentBitmap); Allocation tmpOut = Allocation.CreateFromBitmap(renderScript, outputBitmap); //Intrinsic Gausian blur filter ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.Create(renderScript, Element.U8_4(renderScript)); theIntrinsic.SetRadius(AppSettings.BlurRadiusComment); theIntrinsic.SetInput(tmpIn); theIntrinsic.ForEach(tmpOut); tmpOut.CopyTo(outputBitmap); return(outputBitmap); } catch (Exception e) { Console.WriteLine(e); return(null); } }
public bool Prepare(Context context, Bitmap buffer, float radius) { if (_mRenderScript == null) { try { _mRenderScript = RenderScript.Create(context); _mBlurScript = ScriptIntrinsicBlur.Create(_mRenderScript, Element.U8_4(_mRenderScript)); } catch (Android.Renderscripts.RSRuntimeException e) { if (DEBUG) { throw e; } else { // In release mode, just ignore Release(); return(false); } } } _mBlurScript.SetRadius(radius); _mBlurInput = Allocation.CreateFromBitmap( _mRenderScript, buffer, Allocation.MipmapControl.MipmapNone, AllocationUsage.Script); _mBlurOutput = Allocation.CreateTyped(_mRenderScript, _mBlurInput.Type); return(true); }
private Bitmap CreateBlurredImage(int radius, Bitmap originalBitmap) { // Load a clean bitmap and work from that. //** Asi estaba antes Bitmap originalBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.dog_and_monkeys); // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap; blurredBitmap = Bitmap.CreateBitmap(originalBitmap); // Create the Renderscript instance that will do the work. RenderScript rs = RenderScript.Create(this); // Allocate memory for Renderscript to work with Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, 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(radius); // Start the ScriptIntrinisicBlur script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBitmap); return(blurredBitmap); }
//Retrieves a blurred image public static Drawable Difuminar(Drawable papelTapiz, short blurRadius) { Bitmap originalBitmap = ((BitmapDrawable)papelTapiz).Bitmap; Bitmap blurredBitmap = Bitmap.CreateScaledBitmap(originalBitmap, originalBitmap.Width, originalBitmap.Height, false); RenderScript rs = RenderScript.Create(Application.Context); Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); Allocation output = Allocation.CreateTyped(rs, input.Type); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); script.SetInput(input); if (blurRadius < maxRadius) { script.SetRadius(blurRadius); } script.ForEach(output); output.CopyTo(blurredBitmap); Drawable papelTapizDifuminado = new BitmapDrawable(Android.Content.Res.Resources.System, blurredBitmap); originalBitmap.Recycle(); originalBitmap.Dispose(); blurredBitmap.Recycle(); blurredBitmap.Dispose(); input.Dispose(); output.Dispose(); return(papelTapizDifuminado); }
public Bitmap Transform(Bitmap source) { // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap = Bitmap.CreateBitmap(source); // Allocate memory for Renderscript to work with Allocation input = Allocation.CreateFromBitmap(m_Rs, source, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); Allocation output = Allocation.CreateTyped(m_Rs, input.Type); // Load up an instance of the specific script that we want to use. ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(m_Rs, Element.U8_4(m_Rs)); script.SetInput(input); // Set the blur radius script.SetRadius(m_BlurRadius); // Start the ScriptIntrinisicBlur script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBitmap); if (blurredBitmap != source) { source.Recycle(); } return(blurredBitmap); }
public Bitmap blur(Bitmap bitmap, float radius, int repeat) { if (!IS_BLUR_SUPPORTED) { return(null); } if (radius > MAX_RADIUS) { radius = MAX_RADIUS; } int width = bitmap.Width; int height = bitmap.Height; // Create allocation type Type bitmapType = new Type.Builder(rs, Element.RGBA_8888(rs)) .SetX(width) .SetY(height) .SetMipmaps(false) // We are using MipmapControl.MIPMAP_NONE .Create(); // Create allocation Allocation allocation = Allocation.CreateTyped(rs, bitmapType); // Create blur script ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); blurScript.SetRadius(radius); // Copy data to allocation allocation.CopyFrom(bitmap); // set blur script input blurScript.SetInput(allocation); // invoke the script to blur blurScript.ForEach(allocation); // Repeat the blur for extra effect for (int i = 0; i < repeat; i++) { blurScript.ForEach(allocation); } // copy data back to the bitmap allocation.CopyTo(bitmap); // release memory allocation.Destroy(); blurScript.Destroy(); allocation = null; blurScript = null; return(bitmap); }
private Bitmap Blur() { //Now I am letting the user to risk by letting them to choose to blur the image when the device runs android 10 and beyond if (new ConfigurationManager(AppPreferences.Default).RetrieveAValue(ConfigurationParameters.BlurEnabledForAndroid10) == false) { //Workaround Android Q: IT causes SIGSEV in Android 10 for some reason. XOM related maybe if (Build.VERSION.SdkInt >= BuildVersionCodes.Q) { return(image); } } if (image == null) { return(image); } if (intensity == 0) { return(image); //No need to blur the image. } Bitmap input; if (image.Width > deviceWidth || image.Height > deviceHeight) { input = Bitmap.CreateScaledBitmap(image, deviceWidth, deviceHeight, false); } else { input = Bitmap.CreateScaledBitmap(image, deviceWidth, deviceHeight, true); } try { Bitmap output = Bitmap.CreateBitmap(input); RenderScript rs = RenderScript.Create(context); ScriptIntrinsicBlur intrinsicBlur = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); Allocation inputallocation = Allocation.CreateFromBitmap(rs, input); Allocation outputallocation = Allocation.CreateFromBitmap(rs, output); intrinsicBlur.SetRadius(intensity); intrinsicBlur.SetInput(inputallocation); intrinsicBlur.ForEach(outputallocation); outputallocation.CopyTo(output); return(output); } catch { return(input); } }
public static void BlurBitmapWithRenderscript(RenderScript rs, Bitmap bitmap2) { // this will blur the bitmapOriginal with a radius of 25 // and save it in bitmapOriginal // use this constructor for best performance, because it uses // USAGE_SHARED mode which reuses memory Allocation input = Allocation.CreateFromBitmap(rs, bitmap2); Allocation output = Allocation.CreateTyped(rs, input.Type); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); // must be >0 and <= 25 script.SetRadius(25f); script.SetInput(input); script.ForEach(output); output.CopyTo(bitmap2); }
public static Bitmap Blur(Bitmap BMap, float Radius) { Bitmap MutableBMap = BMap.Copy(Bitmap.Config.Argb8888, true); RenderScript RS = RenderScript.Create(Application.Context); Allocation Input = Allocation.CreateFromBitmap(RS, MutableBMap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); Allocation Output = Allocation.CreateTyped(RS, Input.Type); ScriptIntrinsicBlur Script = ScriptIntrinsicBlur.Create(RS, Element.U8_4(RS)); Script.SetInput(Input); Script.SetRadius(20); Script.ForEach(Output); Output.CopyTo(MutableBMap); return(MutableBMap); }
Bitmap CreateBlurredImage(int radius) { Bitmap originalBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.imagebackground); Bitmap blurredBitmap = Bitmap.CreateBitmap(originalBitmap); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(renderScript, Element.U8_4(renderScript)); Allocation input = Allocation.CreateFromBitmap(renderScript, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); script.SetInput(input); script.SetRadius(radius); Allocation output = Allocation.CreateTyped(renderScript, input.Type); script.ForEach(output); output.CopyTo(blurredBitmap); output.Destroy(); input.Destroy(); script.Destroy(); return(blurredBitmap); }
public void Show() { var obj = (Activity)Xamarin.Forms.Forms.Context; var root = obj.Window.DecorView.FindViewById(Resource.Id.Content); root.DrawingCacheEnabled = true; var b = Bitmap.CreateBitmap(root.GetDrawingCache(true)); root.DrawingCacheEnabled = false; // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap; blurredBitmap = Bitmap.CreateBitmap(b); // Create the Renderscript instance that will do the work. RenderScript rs = RenderScript.Create(obj); // Allocate memory for Renderscript to work with Allocation input = Allocation.CreateFromBitmap(rs, b, Allocation.MipmapControl.MipmapFull, 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, Renderscripts.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(blurredBitmap); dialog = new Dialog(obj, Resource.Style.ThemeNoTitleBar); Drawable d = new BitmapDrawable(blurredBitmap); dialog.Window.SetBackgroundDrawable(d); dialog.Show(); }
private void Init(Context context, IAttributeSet attrs) { // set up the script try { renderScript = RenderScript.Create(context); blurScript = ScriptIntrinsicBlur.Create(renderScript, Element.U8_4(renderScript)); } catch (Java.Lang.RuntimeException ex) { if (ex.Class.Name == "android.support.v8.renderscript.RSRuntimeException") { Console.WriteLine(ex); } else { throw; } } // set the default values BlurRadius = DefaultBlurRadius; DownsampleFactor = DefaultDownsampleFactor; OverlayColor = DefaultOverlayColor; OverlayBackgroundColor = DefaultOverlayBackgroundColor; BlurredView = null; if (attrs != null) { // read any XML values var a = context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.BlurringView, 0, 0); try { BlurRadius = a.GetInteger(Resource.Styleable.BlurringView_blurRadius, DefaultBlurRadius); DownsampleFactor = a.GetInteger(Resource.Styleable.BlurringView_downsampleFactor, DefaultDownsampleFactor); OverlayColor = a.GetColor(Resource.Styleable.BlurringView_overlayColor, DefaultOverlayColor); OverlayBackgroundColor = a.GetColor(Resource.Styleable.BlurringView_overlayBackgroundColor, DefaultOverlayBackgroundColor); } finally { a.Recycle(); } } }
protected override void OnAttachedToWindow() { base.OnAttachedToWindow(); if (useBlur) { rs = RenderScript.Create(Context); if (rs != null) { script = ScriptIntrinsicBlur.Create(rs, Android.Renderscripts.Element.U8_4(rs)); } if (Element != null) { UpdateBackgroundColor(); } } }
Bitmap BlurImage(Bitmap input) { try { var rsScript = RenderScript.Create(Context); var alloc = Allocation.CreateFromBitmap(rsScript, input); var blur = ScriptIntrinsicBlur.Create(rsScript, alloc.Element); blur.SetRadius(12); blur.SetInput(alloc); var result = Bitmap.CreateBitmap(input.Width, input.Height, input.GetConfig()); var outAlloc = Allocation.CreateFromBitmap(rsScript, result); blur.ForEach(outAlloc); outAlloc.CopyTo(result); rsScript.Destroy(); return(result); } catch (Exception e) { Log.Error("Blurrer", "Error while trying to blur, fallbacking. " + e.ToString()); return(input); } }
public Bitmap CreateBlurredImageoffline(Context contexto, int radius, int resid) { // Load a clean bitmap and work from that. WallpaperManager wm = WallpaperManager.GetInstance(this); Drawable d = wm.Drawable; Bitmap originalBitmap; originalBitmap = ((BitmapDrawable)d).Bitmap; if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1) { // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap; blurredBitmap = Bitmap.CreateBitmap(originalBitmap); // Create the Renderscript instance that will do the work. RenderScript rs = RenderScript.Create(contexto); // Allocate memory for Renderscript to work with Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, 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(radius); // Start the ScriptIntrinisicBlur script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBitmap); return(blurredBitmap); } else { return(originalBitmap); } }
private void CreateBlurredImage(int radius) { // Load a clean bitmap and work from that. Bitmap originalBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.dog_and_monkeys); if (blurredBmp != null) { blurredBmp.Recycle(); blurredBmp.Dispose(); blurredBmp = null; } // Create another bitmap that will hold the results of the filter. blurredBmp = Bitmap.CreateBitmap(originalBitmap); // Create the Renderscript instance that will do the work. RenderScript rs = RenderScript.Create(this); // Allocate memory for Renderscript to work with Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, Allocation.UsageScript); 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(radius); // Start Renderscript working. script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBmp); input.Destroy(); input.Dispose(); output.Destroy(); output.Dispose(); }
private Bitmap CreateBlurredImage(int radius, Bitmap originalBitmap) { Bitmap blurredBitmap; blurredBitmap = Bitmap.CreateBitmap(originalBitmap); var rs = RenderScript.Create(Forms.Context); var input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); var output = Allocation.CreateTyped(rs, input.Type); var script = ScriptIntrinsicBlur.Create(rs, Android.Renderscripts.Element.U8_4(rs)); script.SetInput(input); script.SetRadius(radius); script.ForEach(output); output.CopyTo(blurredBitmap); return(blurredBitmap); }
public static Bitmap Blur(Context ctx, Bitmap image) { int width = (int)Math.Round(image.Width * BITMAP_SCALE); int height = (int)Math.Round(image.Height * BITMAP_SCALE); Bitmap inputBitmap = Bitmap.CreateScaledBitmap(image, width, height, false); Bitmap outputBitmap = Bitmap.CreateBitmap(inputBitmap); var rs = RenderScript.Create(ctx); ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.CreateFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.CreateFromBitmap(rs, outputBitmap); theIntrinsic.SetRadius(BLUR_RADIUS); theIntrinsic.SetInput(tmpIn); theIntrinsic.ForEach(tmpOut); tmpOut.CopyTo(outputBitmap); return(outputBitmap); }
public Bitmap FnBlurEffectToImage(Bitmap image) { if (image == null) { return(null); } Bitmap outputBitmap = Bitmap.CreateBitmap(image); RenderScript renderScript = RenderScript.Create(this); Allocation tmpIn = Allocation.CreateFromBitmap(renderScript, image); Allocation tmpOut = Allocation.CreateFromBitmap(renderScript, outputBitmap); //Intrinsic Gausian blur filter ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.Create(renderScript, Element.U8_4(renderScript)); theIntrinsic.SetRadius(10f); theIntrinsic.SetInput(tmpIn); theIntrinsic.ForEach(tmpOut); tmpOut.CopyTo(outputBitmap); return(outputBitmap); }
Bitmap CreateBlurredImage(int radius) { // Load a clean bitmap to work from. Bitmap originalBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.dog_and_monkeys); // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap = Bitmap.CreateBitmap(originalBitmap); // Load up an instance of the specific script that we want to use. // An Element is similar to a C type. The second parameter, Element.U8_4, // tells the Allocation is made up of 4 fields of 8 unsigned bits. ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(renderScript, Element.U8_4(renderScript)); // Create an Allocation for the kernel inputs. Allocation input = Allocation.CreateFromBitmap(renderScript, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script); // Assign the input Allocation to the script. script.SetInput(input); // Set the blur radius script.SetRadius(radius); // Finally we need to create an output allocation to hold the output of the Renderscript. Allocation output = Allocation.CreateTyped(renderScript, input.Type); // Next, run the script. This will run the script over each Element in the Allocation, and copy it's // output to the allocation we just created for this purpose. script.ForEach(output); // Copy the output to the blurred bitmap output.CopyTo(blurredBitmap); // Cleanup. output.Destroy(); input.Destroy(); script.Destroy(); return(blurredBitmap); }
protected override Android.Graphics.Bitmap Transform(Android.Graphics.Bitmap source) { Bitmap outBitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(outBitmap); canvas.DrawBitmap(source, 0, 0, null); RenderScript rs = RenderScript.Create(mContext); Allocation overlayAlloc = Allocation.CreateFromBitmap(rs, outBitmap); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element); blur.SetInput(overlayAlloc); blur.SetRadius(mRadius); blur.ForEach(overlayAlloc); overlayAlloc.CopyTo(outBitmap); source.Recycle(); rs.Destroy(); return(outBitmap); }
public static Bitmap Blur(this Bitmap image, Context context, float blurRadius = 25) { Bitmap outputBitmap = null; if (image != null) { if (blurRadius == 0) { return(image); } if (blurRadius < 1) { blurRadius = 1; } if (blurRadius > 25) { blurRadius = 25; } BLUR_RADIUS = blurRadius; int width = (int)Math.Round(image.Width * BITMAP_SCALE); int height = (int)Math.Round(image.Width * BITMAP_SCALE); Bitmap inputBitmap = Bitmap.CreateScaledBitmap(image, width, height, false); outputBitmap = Bitmap.CreateBitmap(inputBitmap); RenderScript rs = RenderScript.Create(context); ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.CreateFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.CreateFromBitmap(rs, outputBitmap); theIntrinsic.SetRadius(BLUR_RADIUS); theIntrinsic.SetInput(tmpIn); theIntrinsic.ForEach(tmpOut); tmpOut.CopyTo(outputBitmap); } return(outputBitmap); }
private void DatabaseVariable_Updated(object sender, Ao3TrackDatabase.VariableUpdatedEventArgs e) { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { bool.TryParse(e.NewValue, out useBlur); if (useBlur) { if (IsAttachedToWindow) { if (rs == null) { rs = RenderScript.Create(Context); } if (rs != null) { script = ScriptIntrinsicBlur.Create(rs, Android.Renderscripts.Element.U8_4(rs)); } } } else { script?.Dispose(); script = null; sourceCanvas?.Dispose(); sourceCanvas = null; source?.Dispose(); source = null; blurred?.Dispose(); blurred = null; rs?.Dispose(); rs = null; } if (Element != null) { UpdateBackgroundColor(); } }); }
public Drawable Difuminar(Drawable papelTapiz) { //Fondo de escritorio provista por el Argumento que se pasa en <papelTapiz> Bitmap originalBitmap = ((BitmapDrawable)papelTapiz).Bitmap; // Un bitmap null que almacenará la imagen difuminada. Bitmap blurredBitmap; //Asignar a este bitmap la imagen original para trabajar con ella. blurredBitmap = Bitmap.CreateBitmap(originalBitmap); //Crear la instancia de RenderScript que hará el trabajo RenderScript rs = RenderScript.Create(Application.Context); //Alocar memoria para que RenderScript trabaje. Allocation input = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, 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(blurredBitmap); //Scale the bitmap: Bitmap blurredBitMapResized = Bitmap.CreateScaledBitmap(blurredBitmap, 70, 80, false); Drawable papelTapizDifuminado = new BitmapDrawable(blurredBitMapResized); originalBitmap = null; blurredBitmap = null; blurredBitMapResized = null; return(papelTapizDifuminado); }