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 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 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); }
public Bitmap Blur(Bitmap bitmap, float blurRadius) { // Allocation will use the same backing array of pixels as bitmap if created with USAGE_SHARED flag using (var inAllocation = Allocation.CreateFromBitmap(_renderScript, bitmap)) { if (!CanReuseAllocation(bitmap)) { if (_outAllocation != null) { _outAllocation.Destroy(); _outAllocation.Dispose(); } _outAllocation = Allocation.CreateTyped(_renderScript, inAllocation.Type); _lastBitmapWidth = bitmap.Width; _lastBitmapHeight = bitmap.Height; } _blurScript.SetRadius(blurRadius); _blurScript.SetInput(inAllocation); // Do not use inAllocation in forEach, it will caue visual artifacts on blurred bitmap _blurScript.ForEach(_outAllocation); _outAllocation.CopyTo(bitmap); inAllocation.Destroy(); } return(bitmap); }
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); }
private Bitmap CreateResizedImage(Bitmap originalBitmap) { int width = Convert.ToInt32(Math.Round(originalBitmap.Width * BITMAP_SCALE)); int height = Convert.ToInt32(Math.Round(originalBitmap.Height * BITMAP_SCALE)); // Create another bitmap that will hold the results of the filter. Bitmap inputBitmap = Bitmap.CreateScaledBitmap(originalBitmap, width, height, false); Bitmap outputBitmap = Bitmap.CreateBitmap(inputBitmap); // Create the Renderscript instance that will do the work. RenderScript rs = RenderScript.Create(Context); Allocation tmpIn = Allocation.CreateFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.CreateFromBitmap(rs, outputBitmap); // Allocate memory for Renderscript to work with var t = Android.Renderscripts.Type.CreateXY(rs, tmpIn.Element, Convert.ToInt32(width * RESIZE_SCALE), Convert.ToInt32(height * RESIZE_SCALE)); Allocation tmpScratch = Allocation.CreateTyped(rs, t); ScriptIntrinsicResize theIntrinsic = ScriptIntrinsicResize.Create(rs); // Resize the original img down. theIntrinsic.SetInput(tmpIn); theIntrinsic.ForEach_bicubic(tmpScratch); // Resize smaller img up. theIntrinsic.SetInput(tmpScratch); theIntrinsic.ForEach_bicubic(tmpOut); tmpOut.CopyTo(outputBitmap); return(outputBitmap); }
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 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 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 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); } }
/// <summary> /// Converts YUV_420_888 raw data to RGB bitmap. /// </summary> /// <returns>The RGB bitmap.</returns> /// <param name="y">Y</param> /// <param name="u">U</param> /// <param name="v">V</param> /// <param name="width">Width</param> /// <param name="height">Height</param> /// <param name="yRowStride">Y row stride (we know from documentation that PixelStride is 1 for y).</param> /// <param name="uvRowStride">UV row stride (we know from documentation that RowStride is the same for u and v).</param> /// <param name="uvPixelStride">Uv pixel stride (we know from documentation that PixelStride is the same for u and v).</param> public Bitmap Yuv420888ToRgb(byte[] y, byte[] u, byte[] v, int width, int height, int yRowStride, int uvRowStride, int uvPixelStride) { // rs creation just for demo. Create rs just once in onCreate and use it again. //RenderScript rs = (activity as MainActivity).RenderScript; // RenderScript.create(this); RenderScript rs = RenderScript.Create(Android.App.Application.Context); //RenderScript rs = MainActivity.rs; ScriptC_yuv420888 mYuv420 = new ScriptC_yuv420888(rs); // Y,U,V are defined as global allocations, the out-Allocation is the Bitmap. // Note also that uAlloc and vAlloc are 1-dimensional while yAlloc is 2-dimensional. RType.Builder typeUcharY = new RType.Builder(rs, Element.U8(rs)); typeUcharY.SetX(yRowStride).SetY(height); Allocation yAlloc = Allocation.CreateTyped(rs, typeUcharY.Create()); yAlloc.CopyFrom(y); mYuv420.Set_ypsIn(yAlloc); RType.Builder typeUcharUV = new RType.Builder(rs, Element.U8(rs)); // note that the size of the u's and v's are as follows: // ( (width/2)*PixelStride + padding ) * (height/2) // = (RowStride ) * (height/2) // but I noted that on the S7 it is 1 less... typeUcharUV.SetX(u.Length); Allocation uAlloc = Allocation.CreateTyped(rs, typeUcharUV.Create()); uAlloc.CopyFrom(u); mYuv420.Set_uIn(uAlloc); Allocation vAlloc = Allocation.CreateTyped(rs, typeUcharUV.Create()); vAlloc.CopyFrom(v); mYuv420.Set_vIn(vAlloc); // handover parameters mYuv420.Set_picWidth(width); mYuv420.Set_uvRowStride(uvRowStride); mYuv420.Set_uvPixelStride(uvPixelStride); Bitmap outBitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); Allocation outAlloc = Allocation.CreateFromBitmap(rs, outBitmap, Allocation.MipmapControl.MipmapNone, Allocation.UsageScript); Script.LaunchOptions lo = new Script.LaunchOptions(); lo.SetX(0, width); // by this we ignore the y’s padding zone, i.e. the right side of x between width and yRowStride lo.SetY(0, height); mYuv420.ForEach_doConvert(outAlloc, lo); outAlloc.CopyTo(outBitmap); return(outBitmap); }
protected bool Prepare() { var width = _mBlurredView.Width; var height = _mBlurredView.Height; if (_mBlurringCanvas != null && !_mDownsampleFactorChanged && _mBlurredViewWidth == width && _mBlurredViewHeight == height) { return(true); } _mDownsampleFactorChanged = false; _mBlurredViewWidth = width; _mBlurredViewHeight = height; var scaledWidth = width / _mDownsampleFactor; var scaledHeight = height / _mDownsampleFactor; // The following manipulation is to avoid some RenderScript artifacts at the edge. scaledWidth = scaledWidth - scaledWidth % 4 + 4; scaledHeight = scaledHeight - scaledHeight % 4 + 4; if (_mBlurredBitmap == null || _mBlurredBitmap.Width != scaledWidth || _mBlurredBitmap.Height != scaledHeight) { _mBitmapToBlur = Bitmap.CreateBitmap(scaledWidth, scaledHeight, Bitmap.Config.Argb8888); if (_mBitmapToBlur == null) { return(false); } _mBlurredBitmap = Bitmap.CreateBitmap(scaledWidth, scaledHeight, Bitmap.Config.Argb8888); if (_mBlurredBitmap == null) { return(false); } } _mBlurringCanvas = new Canvas(_mBitmapToBlur); _mBlurringCanvas.Scale(1f / _mDownsampleFactor, 1f / _mDownsampleFactor); _mBlurInput = Allocation.CreateFromBitmap(_mRenderScript, _mBitmapToBlur, Allocation.MipmapControl.MipmapNone, AllocationUsage.Script); _mBlurOutput = Allocation.CreateTyped(_mRenderScript, _mBlurInput.Type); return(true); }
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); }
protected bool prepare() { int width = mBlurredView.Width; int height = mBlurredView.Height; if (mBlurringCanvas == null || mDownsampleFactorChanged || mBlurredViewWidth != width || mBlurredViewHeight != height) { mDownsampleFactorChanged = false; mBlurredViewWidth = width; mBlurredViewHeight = height; int scaledWidth = width / mDownsampleFactor; int scaledHeight = height / mDownsampleFactor; // The following manipulation is to avoid some RenderScript artifacts at the edge. scaledWidth = scaledWidth - scaledWidth % 4 + 4; scaledHeight = scaledHeight - scaledHeight % 4 + 4; if (mBlurredBitmap == null || mBlurredBitmap.Width != scaledWidth || mBlurredBitmap.Height != scaledHeight) { mBitmapToBlur = Bitmap.CreateBitmap(scaledWidth, scaledHeight, Bitmap.Config.Argb8888); if (mBitmapToBlur == null) { return(false); } mBlurredBitmap = Bitmap.CreateBitmap(scaledWidth, scaledHeight, Bitmap.Config.Argb8888); if (mBlurredBitmap == null) { return(false); } } mBlurringCanvas = new Canvas(mBitmapToBlur); mBlurringCanvas.Scale(1f / mDownsampleFactor, 1f / mDownsampleFactor); mBlurInput = Allocation.CreateFromBitmap(mRenderScript, mBitmapToBlur, Allocation.MipmapControl.MipmapNone, AllocationUsage.Script); mBlurOutput = Allocation.CreateTyped(mRenderScript, mBlurInput.Type); } return(true); }
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(); }
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); } }
private bool Prepare() { int width = BlurredView.Width; int height = BlurredView.Height; if (blurringCanvas == null || downsampleFactorChanged || blurredViewWidth != width || blurredViewHeight != height) { downsampleFactorChanged = false; blurredViewWidth = width; blurredViewHeight = height; int scaledWidth = width / downsampleFactor; int scaledHeight = height / downsampleFactor; scaledWidth = scaledWidth - scaledWidth % 4 + 4; scaledHeight = scaledHeight - scaledHeight % 4 + 4; if (blurredBitmap == null || blurredBitmap.Width != scaledWidth || blurredBitmap.Height != scaledHeight) { bitmapToBlur = Bitmap.CreateBitmap(scaledWidth, scaledHeight, Bitmap.Config.Argb8888); if (bitmapToBlur == null) { return(false); } blurredBitmap = Bitmap.CreateBitmap(scaledWidth, scaledHeight, Bitmap.Config.Argb8888); if (blurredBitmap == null) { return(false); } } blurringCanvas = new Canvas(bitmapToBlur); blurringCanvas.Scale(1f / downsampleFactor, 1f / downsampleFactor); if (renderScript != null) { blurInput = Allocation.CreateFromBitmap(renderScript, bitmapToBlur, Allocation.MipmapControl.MipmapNone, Allocation.UsageScript); blurOutput = Allocation.CreateTyped(renderScript, blurInput.Type); } } return(true); }
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(); }
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); } }
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); }
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 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); }