List of usage examples for android.renderscript Allocation copyTo
public void copyTo(float[] d)
From source file:Main.java
public static Bitmap blurBitmap(Context context, Bitmap bitmap) { Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); RenderScript rs = RenderScript.create(context); ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation allIn = Allocation.createFromBitmap(rs, bitmap); Allocation allOut = Allocation.createFromBitmap(rs, outBitmap); blurScript.setRadius(8f);/*from w w w . j av a 2s . co m*/ blurScript.setInput(allIn); blurScript.forEach(allOut); allOut.copyTo(outBitmap); bitmap.recycle(); rs.destroy(); return outBitmap; }
From source file:Main.java
public static Bitmap blurBitmap(Context context, Bitmap bitmap, float radius) { Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); RenderScript rs = RenderScript.create(context); ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation allIn = Allocation.createFromBitmap(rs, bitmap); Allocation allOut = Allocation.createFromBitmap(rs, bitmap); blurScript.setRadius(radius);/*ww w .jav a 2 s . c o m*/ blurScript.setInput(allIn); blurScript.forEach(allOut); allOut.copyTo(outBitmap); bitmap.recycle(); rs.destroy(); return outBitmap; }
From source file:Main.java
/** * https://futurestud.io/blog/how-to-blur-images-efficiently-with-androids-renderscript * https://developer.xamarin.com/recipes/android/other_ux/drawing/blur_an_image_with_renderscript/ * * @param context/*from w w w . j a v a 2s . com*/ * @param image original bitmap * @param width output bitmap width * @param height output bitmap height * @param blurRadius blur radius ; blurRadius in section (0,25] * @return */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap blur(Context context, Bitmap image, int width, int height, int blurRadius) { 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(blurRadius); theIntrinsic.setInput(tmpIn); theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); rs.destroy(); return outputBitmap; }
From source file:Main.java
public static Bitmap blurLight(Context context, Bitmap image) { int width = Math.round(image.getWidth() * BITMAP_SCALE_LIGHT); int height = Math.round(image.getHeight() * BITMAP_SCALE_LIGHT); 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_LIGHT); theIntrinsic.setInput(tmpIn);/*from www . j a va 2 s . c o m*/ theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap blur(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);/*from w ww.j a v a2 s . co m*/ theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; }
From source file:Main.java
public static void blur(Context context, Bitmap bkg, View view, int width, int height) { float radius = 20; Log.i("hulixia", bkg.getWidth() + "w,h" + bkg.getDensity()); Bitmap overlay = Bitmap.createBitmap(bkg.getWidth(), bkg.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft(), -view.getTop()); canvas.drawBitmap(bkg, 0, 0, null);/*from www .ja v a 2s . c o m*/ 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.setBackground(new BitmapDrawable(context.getResources(), overlay)); rs.destroy(); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static Bitmap blurBitmap(Bitmap src, float blurRadius, Context context) { RenderScript rs = RenderScript.create(context); Bitmap.Config conf = Bitmap.Config.ARGB_8888; Bitmap blurredBitmap = Bitmap.createBitmap(src.getWidth(), src.getHeight(), conf); final Allocation input = Allocation.createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);//w w w .j a va2 s . c o m final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(blurRadius); script.setInput(input); script.forEach(output); output.copyTo(blurredBitmap); return blurredBitmap; }
From source file:Main.java
public static Bitmap makeBlur(Context context, Bitmap sentBitmap, int radius) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { 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);//from w ww . ja v a 2s .co m script.setInput(input); script.forEach(output); output.copyTo(bitmap); return bitmap; } return null; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap fastBlur(Context context, Bitmap bm, int radius) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Bitmap bitmap = bm.copy(bm.getConfig(), true); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, bm, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius);/* w ww . j a v a2 s. co m*/ script.setInput(input); script.forEach(output); output.copyTo(bitmap); // clean up renderscript resources rs.destroy(); input.destroy(); output.destroy(); script.destroy(); return bitmap; } return null; }
From source file:Main.java
/** * Return the histograms for each color channel (interleaved). * * @param rs a {@link RenderScript} context to use. * @param bmap a {@link Bitmap} to generate the histograms for. * @return an array containing NUM_CHANNELS * COLOR_BIT_DEPTH histogram bucket values, with * the color channels interleaved./*from w ww. j ava 2s. co m*/ */ public static int[] calcHistograms(RenderScript rs, Bitmap bmap) { ScriptIntrinsicHistogram hist = ScriptIntrinsicHistogram.create(rs, Element.U8_4(rs)); Allocation sums = Allocation.createSized(rs, Element.I32_4(rs), COLOR_BIT_DEPTH); // Setup input allocation (ARGB 8888 bitmap). Allocation input = Allocation.createFromBitmap(rs, bmap); hist.setOutput(sums); hist.forEach(input); int[] output = new int[COLOR_BIT_DEPTH * NUM_CHANNELS]; sums.copyTo(output); return output; }