//define this only once if blurring multiple times RenderScript rs = RenderScript.create(context); (...) //this will blur the bitmapOriginal with a radius of 8 and save it in bitmapOriginal final Allocation input = Allocation.createFromBitmap(rs, bitmapOriginal); //use this constructor for best performance, because it uses USAGE_SHARED mode which reuses memory final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(8f); script.setInput(input); script.forEach(output); output.copyTo(bitmapOriginal);
final RenderScript rs = RenderScript.create( myAndroidContext ); final Allocation input = Allocation.createFromBitmap( rs, photo, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT ); final Allocation output = Allocation.createTyped( rs, input.getType() ); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create( rs, Element.U8_4( rs ) ); script.setRadius( myBlurRadius /* e.g. 3.f */ ); script.setInput( input ); script.forEach( output ); output.copyTo( photo );
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
/** * @param bitmap bitmap to blur * @param blurRadius blur radius (1..25) * @return blurred bitmap */ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) @Override public final Bitmap blur(Bitmap bitmap, float blurRadius) { //Allocation will use the same backing array of pixels as bitmap if created with USAGE_SHARED flag Allocation inAllocation = Allocation.createFromBitmap(renderScript, bitmap); if (!canReuseAllocation(bitmap)) { if (outAllocation != null) { outAllocation.destroy(); } outAllocation = Allocation.createTyped(renderScript, inAllocation.getType()); lastBitmapWidth = bitmap.getWidth(); lastBitmapHeight = bitmap.getHeight(); } blurScript.setRadius(blurRadius); blurScript.setInput(inAllocation); //do not use inAllocation in forEach. it will cause visual artifacts on blurred Bitmap blurScript.forEach(outAllocation); outAllocation.copyTo(bitmap); inAllocation.destroy(); return bitmap; }
public Bitmap blur(Bitmap src, int radius) { final Allocation input = Allocation.createFromBitmap(rs, src); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); return src; }
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); output = Allocation.createTyped(rs, input.getType()); blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); output = Allocation.createTyped(rs, input.getType()); blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap rsBlur(Context context, Bitmap toTransform, int radius) { RenderScript renderScript = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(renderScript, toTransform); Allocation output = Allocation.createTyped(renderScript, input.getType()); ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript)); scriptIntrinsicBlur.setInput(input); scriptIntrinsicBlur.setRadius(radius); scriptIntrinsicBlur.forEach(output); output.copyTo(toTransform); renderScript.destroy(); return toTransform; }
public void copyDoublesTo(double[] entries, Allocation target) { if (!target.getType().getElement().isCompatible(Element.F64(mRS))) { throw new RSRuntimeException("Type mismatch: Element != F64"); } if (target.getType().getCount() != entries.length) { throw new RSRuntimeException("Type mismatch: wrong # of entries"); } mScript.bind_target(target); for(int i=0; i!=entries.length; ++i) { mScript.invoke_setTargetEntry(i, entries[i]); } }
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); output = Allocation.createTyped(rs, input.getType()); blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Bitmap inputBitmap = Bitmap.createScaledBitmap(artistImage, artistImage.getWidth(), artistImage.getHeight(), false); Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); RenderScript rs = RenderScript.create(context); for (int i = 0; i < 10; i++){ final Allocation input = Allocation.createFromBitmap(rs, outputBitmap); //use this constructor for best performance, because it uses USAGE_SHARED mode which reuses memory final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(25F); script.setInput(input); script.forEach(output); output.copyTo(outputBitmap); }
Bitmap screen = [screenshot bitmap]; RenderScript rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, screen, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(25); script.setInput(input); script.forEach(output); output.copyTo(screen); return screen;
Bitmap blackbitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig()); RenderScript mRS = RenderScript.create(TouchEmbroidery.activity); ScriptC_blackcheck script = new ScriptC_blackcheck(mRS); Allocation allocationRaster0 = Allocation.createFromBitmap( mRS, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT ); Allocation allocationRaster1 = Allocation.createTyped(mRS, allocationRaster0.getType()); script.forEach_root(allocationRaster0, allocationRaster1); allocationRaster1.copyTo(blackbitmap);
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static Bitmap fastblur16(Bitmap source, int radius, Context ctx) { Bitmap bitmap = source.copy(source.getConfig(), true); RenderScript rs = RenderScript.create(ctx); Allocation input = Allocation.createFromBitmap(rs, source, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(bitmap); return bitmap; }
// Whatever.java public void copyDoublesTo(double[] entries, Allocation target) throws IOException { if (!target.getType().getElement().isCompatible(Element.F64(mRS))) throw new RSRuntimeException("Type mismatch: Element != F64"); if (target.getType().getCount() != entries.length) throw new RSRuntimeException("Type mismatch: wrong # of entries"); mScript.bind_target(target); ByteArrayOutputStream bytes = new ByteArrayOutputStream(Double.SIZE * dim); DataOutputStream longs = new DataOutputStream(bytes); long temp; for(int i=0; i!=dim; ++i) { temp = Double.doubleToLongBits(entries[i]); // reverse byte order: temp = Long.reverseBytes(temp); longs.writeLong(temp); } target.copyFromUnchecked(bytes.toByteArray()); }
private static Bitmap blurRenderScript(Context context, Bitmap smallBitmap, int radius) { RenderScript rs = RenderScript.create(context); Bitmap blurredBitmap = smallBitmap.copy(Bitmap.Config.ARGB_8888, true); Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED); Allocation output = Allocation.createTyped(rs, input.getType()); // 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); script.setRadius(radius); script.forEach(output); output.copyTo(blurredBitmap); return blurredBitmap; }