use of android.renderscript.RenderScript in project DevRing by LJYcoder.
the class ImageUtil method rsBlur.
/**
* 使用RenderScript实现的高斯模糊效果(性能较高,模糊半径0-25,越大越模糊)
* 需在module下的build.gradle中加入以下配置才可使用
* renderscriptTargetApi 19
* renderscriptSupportModeEnabled true
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap rsBlur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
RenderScript rs = null;
try {
rs = RenderScript.create(context);
Allocation input = Allocation.createFromBitmap(rs, bitmap);
Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
blur.setRadius(radius);
blur.setInput(input);
blur.forEach(output);
output.copyTo(bitmap);
} finally {
if (rs != null) {
rs.destroy();
}
}
return bitmap;
}
use of android.renderscript.RenderScript in project MVP by yuchengren.
the class BlurUtil method rsBlur.
public static Bitmap rsBlur(Context context, Bitmap bitmap, float radius) {
// Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
// Instantiate a new Renderscript
RenderScript rs = RenderScript.create(context.getApplicationContext());
// Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
// Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
// Set the radius of the blur: 0 < radius <= 25
blurScript.setRadius(radius);
// Perform the Renderscript
blurScript.setInput(allIn);
blurScript.forEach(allOut);
// Copy the final bitmap created by the out Allocation to the outBitmap
allOut.copyTo(outBitmap);
// recycle the original bitmap
bitmap.recycle();
// After finishing everything, we destroy the Renderscript.
rs.destroy();
return outBitmap;
}
use of android.renderscript.RenderScript in project EnableHands by LeviWGG.
the class ImageUtils method renderScriptBlur.
/**
* Return the blur bitmap using render script.
*
* @param src The source of bitmap.
* @param radius The radius(0...25).
* @param recycle True to recycle the source of bitmap, false otherwise.
* @return the blur bitmap
*/
@TargetApi(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(BaseUtils.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;
}
use of android.renderscript.RenderScript in project EnableHands by LeviWGG.
the class ImageUtils method renderScriptBlur.
/**
* Return the blur bitmap using render script.
*
* @param src The source of bitmap.
* @param radius The radius(0...25).
* @param recycle True to recycle the source of bitmap, false otherwise.
* @return the blur bitmap
*/
@TargetApi(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(MyApplication.getMyContext());
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;
}
use of android.renderscript.RenderScript in project android_frameworks_base by DirtyUnicorns.
the class ColorUtils method blurBitmap.
public static Bitmap blurBitmap(Context context, Bitmap bmp, int radius) {
Bitmap out = Bitmap.createBitmap(bmp);
RenderScript rs = RenderScript.create(context);
Allocation input = Allocation.createFromBitmap(rs, bmp, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
Allocation output = Allocation.createTyped(rs, input.getType());
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
script.setRadius(radius);
script.forEach(output);
output.copyTo(out);
rs.destroy();
return out;
}
Aggregations