Java Code Examples for android.renderscript.ScriptIntrinsicBlur#setRadius()
The following examples show how to use
android.renderscript.ScriptIntrinsicBlur#setRadius() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlurTransformation.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(bitmapScaleFactor, bitmapScaleFactor); Bitmap blurredBitmap = Bitmap.createBitmap(toTransform, 0, 0, outWidth, outHeight, scaleMatrix, true); Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setInput(input); script.setRadius(blurRadius); script.forEach(output); output.copyTo(blurredBitmap); return blurredBitmap; }
Example 2
Source File: BlurBuilder.java From Audinaut with GNU General Public License v3.0 | 6 votes |
private static Bitmap blur_real(Context context, Bitmap image) { int width = Math.round(image.getWidth() * BITMAP_SCALE); int height = Math.round(image.getHeight() * BITMAP_SCALE); Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); Bitmap 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; }
Example 3
Source File: BlurTransform.java From android-tv-leanback with Apache License 2.0 | 6 votes |
@Override public Bitmap transform(Bitmap bitmap) { // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap = Bitmap.createBitmap(bitmap); // Allocate memory for Renderscript to work with Allocation input = Allocation.createFromBitmap(rs, bitmap, 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); // Set the blur radius script.setRadius(20); // Start the ScriptIntrinisicBlur script.forEach(output); // Copy the output to the blurred bitmap output.copyTo(blurredBitmap); bitmap.recycle(); return blurredBitmap; }
Example 4
Source File: BlurTransform.java From android-tv-leanback with Apache License 2.0 | 6 votes |
@Override public Bitmap transform(Bitmap bitmap) { // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap = Bitmap.createBitmap(bitmap); // Allocate memory for Renderscript to work with Allocation input = Allocation.createFromBitmap(rs, bitmap, 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); // Set the blur radius script.setRadius(20); // Start the ScriptIntrinisicBlur script.forEach(output); // Copy the output to the blurred bitmap output.copyTo(blurredBitmap); bitmap.recycle(); return blurredBitmap; }
Example 5
Source File: BlurTransform.java From android-tv-leanback with Apache License 2.0 | 6 votes |
@Override public Bitmap transform(Bitmap bitmap) { // Create another bitmap that will hold the results of the filter. Bitmap blurredBitmap = Bitmap.createBitmap(bitmap); // Allocate memory for Renderscript to work with Allocation input = Allocation.createFromBitmap(rs, bitmap, 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); // Set the blur radius script.setRadius(20); // Start the ScriptIntrinisicBlur script.forEach(output); // Copy the output to the blurred bitmap output.copyTo(blurredBitmap); bitmap.recycle(); return blurredBitmap; }
Example 6
Source File: Blur.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) { final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); final RenderScript rs = RenderScript.create(context); 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)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(bitmap); sentBitmap.recycle(); rs.destroy(); input.destroy(); output.destroy(); script.destroy(); return bitmap; }
Example 7
Source File: TwitterCoverListView.java From TwitterCover-Android with MIT License | 5 votes |
public Bitmap renderScriptBlur(Bitmap bitmap, int radius) { Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); RenderScript rs = RenderScript.create(mContext); ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation allIn = Allocation.createFromBitmap(rs, bitmap); Allocation allOut = Allocation.createFromBitmap(rs, outBitmap); blurScript.setRadius(radius); blurScript.setInput(allIn); blurScript.forEach(allOut); allOut.copyTo(outBitmap); rs.destroy(); return outBitmap; }
Example 8
Source File: RxImageTool.java From RxTools-master with Apache License 2.0 | 5 votes |
/** * renderScript模糊图片 * <p>API大于17</p> * * @param src 源图片 * @param radius 模糊度(0...25) * @return 模糊后的图片 */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap renderScriptBlur( Bitmap src, float radius) { if (isEmptyBitmap(src)) return null; RenderScript rs = null; try { rs = RenderScript.create(RxTool.getContext()); rs.setMessageHandler(new RenderScript.RSMessageHandler()); Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation .USAGE_SCRIPT); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); if (radius > 25) { radius = 25.0f; } else if (radius <= 0) { radius = 1.0f; } blurScript.setInput(input); blurScript.setRadius(radius); blurScript.forEach(output); output.copyTo(src); } finally { if (rs != null) { rs.destroy(); } } return src; }
Example 9
Source File: TicketView.java From TicketView with Apache License 2.0 | 5 votes |
private void generateShadow() { if (isJellyBeanAndAbove() && !isInEditMode()) { if (mShadowBlurRadius == 0f) return; if (mShadow == null) { mShadow = Bitmap.createBitmap(getWidth(), getHeight(), ALPHA_8); } else { mShadow.eraseColor(TRANSPARENT); } Canvas c = new Canvas(mShadow); c.drawPath(mPath, mShadowPaint); if (mShowBorder) { c.drawPath(mPath, mShadowPaint); } RenderScript rs = RenderScript.create(getContext()); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8(rs)); Allocation input = Allocation.createFromBitmap(rs, mShadow); Allocation output = Allocation.createTyped(rs, input.getType()); blur.setRadius(mShadowBlurRadius); blur.setInput(input); blur.forEach(output); output.copyTo(mShadow); input.destroy(); output.destroy(); blur.destroy(); } }
Example 10
Source File: UIsUtils.java From letv with Apache License 2.0 | 5 votes |
@TargetApi(17) public static Bitmap picBlur(Context context, Bitmap bitmap, Float radius) { Bitmap outPutBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); RenderScript rs = RenderScript.create(context); Allocation allIn = Allocation.createFromBitmap(rs, bitmap); Allocation allOut = Allocation.createFromBitmap(rs, outPutBitmap); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); blur.setInput(allIn); blur.setRadius(TitleBar.SHAREBTN_RIGHT_MARGIN); blur.forEach(allOut); allIn.copyTo(outPutBitmap); rs.destroy(); return outPutBitmap; }
Example 11
Source File: ImageJpegPlugin.java From image_jpeg with MIT License | 5 votes |
public Bitmap blurImage(Bitmap bm, int blur, int blurZoom) { if (blur > 0 && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { RenderScript rs = RenderScript.create(mRegistrar.activity()); ScriptIntrinsicBlur _blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); int w = bm.getWidth(); int h = bm.getHeight(); Bitmap _temp; if (blurZoom == 0) { _temp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); } else { int tw = w / blurZoom; int th = h / blurZoom; bm = Bitmap.createScaledBitmap(bm, tw, th, false); _temp = Bitmap.createBitmap(tw, th, Bitmap.Config.ARGB_8888); } Allocation _in = Allocation.createFromBitmap(rs, bm); Allocation _out = Allocation.createFromBitmap(rs, _temp); _blur.setRadius(Math.min(25.0f, (((float) blur) / 100.0f) * 25.0f)); // 0 ~ 25 _blur.setInput(_in); _blur.forEach(_out); _out.copyTo(_temp); rs.destroy(); if (blurZoom == 0) return Bitmap.createBitmap(_temp); else return Bitmap.createScaledBitmap(_temp, w, h, true); } else return bm; }
Example 12
Source File: BlurTask.java From react-native-blur-overlay with MIT License | 5 votes |
/** * * @param rs RenderScript Context * @param image screenshot bitmap * @param Radius integer between 1 to 24 * @param brightness -255..255 0 is default * @return blurred Bitmap */ private static Bitmap blur(RenderScript rs, Bitmap image, int Radius, float brightness, float factor) { Bitmap outputBitmap; if(Radius > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { outputBitmap = Bitmap.createBitmap(image.getWidth(),image.getHeight(), Bitmap.Config.ARGB_8888); ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.createFromBitmap(rs, image); Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); theIntrinsic.setRadius(Radius/factor); theIntrinsic.setInput(tmpIn); theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); } else { outputBitmap = image; } if(brightness!=0){ ColorMatrix cm = new ColorMatrix(new float[] { (float) 1, 0, 0, 0, brightness, 0, (float) 1, 0, 0, brightness, 0, 0, (float) 1, 0, brightness, 0, 0, 0, 1, 0 }); Canvas canvas = new Canvas(outputBitmap); Paint paint = new Paint(); paint.setColorFilter(new ColorMatrixColorFilter(cm)); canvas.drawBitmap(outputBitmap, 0, 0, paint); } return outputBitmap; }
Example 13
Source File: RenderScriptBlurFilter.java From fresco with MIT License | 5 votes |
/** * Not-in-place intrinsic Gaussian blur filter using {@link ScriptIntrinsicBlur} and {@link * RenderScript}. This require an Android versions >= 4.2. * * @param dest The {@link Bitmap} where the blurred image is written to. * @param src The {@link Bitmap} containing the original image. * @param context The {@link Context} necessary to use {@link RenderScript} * @param radius The radius of the blur with a supported range 0 < radius <= {@link * #BLUR_MAX_RADIUS} */ @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void blurBitmap( final Bitmap dest, final Bitmap src, final Context context, final int radius) { Preconditions.checkNotNull(dest); Preconditions.checkNotNull(src); Preconditions.checkNotNull(context); Preconditions.checkArgument(radius > 0 && radius <= BLUR_MAX_RADIUS); RenderScript rs = null; try { rs = RenderScript.create(context); // Create an Intrinsic Blur Script using the Renderscript ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); // Create the input/output allocations with Renderscript and the src/dest bitmaps Allocation allIn = Allocation.createFromBitmap(rs, src); Allocation allOut = Allocation.createFromBitmap(rs, dest); // Set the radius of the blur blurScript.setRadius(radius); blurScript.setInput(allIn); blurScript.forEach(allOut); allOut.copyTo(dest); blurScript.destroy(); allIn.destroy(); allOut.destroy(); } finally { if (rs != null) { rs.destroy(); } } }
Example 14
Source File: BlurTransformation.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true); // Allocate memory for Renderscript to work with //分配用于渲染脚本的内存 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); // Set the blur radius //设置模糊半径 script.setRadius(radius); // Start the ScriptIntrinsicBlur //启动 ScriptIntrinsicBlur, script.forEach(output); // Copy the output to the blurred bitmap //将输出复制到模糊的位图 output.copyTo(blurredBitmap); return blurredBitmap; }
Example 15
Source File: ZigzagView.java From ZigzagView with Apache License 2.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.KITKAT) private void drawShadow() { shadow = Bitmap.createBitmap(getWidth(), getHeight(), ALPHA_8); shadow.eraseColor(TRANSPARENT); Canvas c = new Canvas(shadow); c.drawPath(pathZigzag, paintShadow); RenderScript rs = RenderScript.create(getContext()); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8(rs)); Allocation input = Allocation.createFromBitmap(rs, shadow); Allocation output = Allocation.createTyped(rs, input.getType()); blur.setRadius(zigzagElevation); blur.setInput(input); blur.forEach(output); output.copyTo(shadow); input.destroy(); output.destroy(); }
Example 16
Source File: GlideTransformUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 模糊图片处理 * @param context {@link Context} * @param image 待模糊的图片 * @param outWidth 输出的宽度 * @param outHeight 输出的高度 * @return 模糊处理后的 Bitmap */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public Bitmap blurBitmap(Context context, Bitmap image, float blurRadius, int outWidth, int outHeight) { // 将缩小后的图片做为预渲染的图片 Bitmap inputBitmap = Bitmap.createScaledBitmap(image, outWidth, outHeight, false); // 创建一张渲染后的输出图片 Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); // 创建 RenderScript 内核对象 RenderScript rs = RenderScript.create(context); // 创建一个模糊效果的 RenderScript 的工具对象 ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); // 由于 RenderScript 并没有使用 VM 来分配内存, 所以需要使用 Allocation 类来创建和分配内存空间 // 创建 Allocation 对象的时候其实内存是空的, 需要使用 copyTo() 将数据填充进去 Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); // 设置渲染的模糊程度, 25f 是最大模糊度 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { blurScript.setRadius(blurRadius); } // 设置 blurScript 对象的输入内存 blurScript.setInput(tmpIn); // 将输出数据保存到输出内存中 blurScript.forEach(tmpOut); // 将数据填充到 Allocation 中 tmpOut.copyTo(outputBitmap); return outputBitmap; }
Example 17
Source File: BlurTransformation.java From AcgClub with MIT License | 5 votes |
private Bitmap doBlur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException { RenderScript rs = null; Allocation input = null; Allocation output = null; ScriptIntrinsicBlur blur = null; try { rs = RenderScript.create(context); rs.setMessageHandler(new RenderScript.RSMessageHandler()); 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)); blur.setInput(input); blur.setRadius(radius); blur.forEach(output); output.copyTo(bitmap); } finally { if (rs != null) { rs.destroy(); } if (input != null) { input.destroy(); } if (output != null) { output.destroy(); } if (blur != null) { blur.destroy(); } } return bitmap; }
Example 18
Source File: GaussianBlur.java From AndroidUI with MIT License | 5 votes |
/** * 通过RenderScript进行图片模糊 * @param bkg 需要模糊的bitmap * @param radius 模糊半径,RenderScript规定范围为[1,25] * @param view 显示模糊图片的ImageView * @param context 上下文 * @return 消耗时间,单位毫秒(ms) */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static long blurByRenderScript(Bitmap bkg,int radius, ImageView view,Context context) { long startMs = System.currentTimeMillis(); float scaleFactor = 8; int width = (int)(view.getMeasuredWidth()/scaleFactor); int height = (int)(view.getMeasuredHeight()/scaleFactor); Bitmap overlay = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.scale(1 / scaleFactor, 1 / scaleFactor); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bkg, 0, 0, paint); RenderScript rs = RenderScript.create(context); Allocation overlayAlloc = Allocation.createFromBitmap(rs, overlay); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, overlayAlloc.getElement()); blur.setInput(overlayAlloc); blur.setRadius(radius); blur.forEach(overlayAlloc); overlayAlloc.copyTo(overlay); view.setImageBitmap(overlay); rs.destroy(); return System.currentTimeMillis() - startMs; }
Example 19
Source File: ImageUtils.java From Android-utils with Apache License 2.0 | 5 votes |
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap renderScriptBlur(final Bitmap src, @FloatRange( from = 0, to = 25, fromInclusive = false ) final float radius, final boolean recycle) { RenderScript rs = null; Bitmap ret = recycle ? src : src.copy(src.getConfig(), true); try { rs = RenderScript.create(UtilsApp.getApp()); rs.setMessageHandler(new RenderScript.RSMessageHandler()); Allocation input = Allocation.createFromBitmap(rs, ret, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); blurScript.setInput(input); blurScript.setRadius(radius); blurScript.forEach(output); output.copyTo(ret); } finally { if (rs != null) { rs.destroy(); } } return ret; }
Example 20
Source File: BlurTransformation.java From a with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) { Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true); // Allocate memory for Renderscript to work with //分配用于渲染脚本的内存 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); // Set the blur radius //设置模糊半径 script.setRadius(radius); // Start the ScriptIntrinsicBlur //启动 ScriptIntrinsicBlur, script.forEach(output); // Copy the output to the blurred bitmap //将输出复制到模糊的位图 output.copyTo(blurredBitmap); return blurredBitmap; }