use of android.renderscript.Allocation in project SmartCampus by Vegen.
the class CommonUtils method blur.
public static void blur(Bitmap bkg, View view, ImageView forecastBlur) {
long start = System.currentTimeMillis();
float radius = 18;
float scaleFactor = 1.0f;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor), (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
// canvas.translate(-view.getLeft(), -view.getTop());
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
canvas.drawBitmap(bkg, 0, 0, null);
RenderScript rs = RenderScript.create(MyApplication.getInstance());
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);
forecastBlur.setImageDrawable(new BitmapDrawable(MyApplication.getInstance().getResources(), overlay));
rs.destroy();
}
Log.e("cost", System.currentTimeMillis() - start + "");
}
use of android.renderscript.Allocation in project vlc-android by videolan.
the class UiTools method blurBitmap.
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blurBitmap(Bitmap bitmap, float radius) {
if (bitmap == null || bitmap.getConfig() == null)
return null;
// 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.Config.ARGB_8888);
// Instantiate a new Renderscript
RenderScript rs = RenderScript.create(VLCApplication.getAppContext());
// 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
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);
// After finishing everything, we destroy the Renderscript.
rs.destroy();
return outBitmap;
}
use of android.renderscript.Allocation in project SmartMesh_Android by SmartMeshFoundation.
the class BitmapUtils method blurBitmap.
public static Bitmap blurBitmap(Context context, Bitmap sentBitmap) {
if (Build.VERSION.SDK_INT > 16) {
try {
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), false);
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(12.0f);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
return bitmap;
} catch (Exception e) {
return sentBitmap;
} catch (OutOfMemoryError err) {
return sentBitmap;
}
} else {
return sentBitmap;
}
}
use of android.renderscript.Allocation in project PolarrCameraAndroidSDK by Polarrco.
the class MainActivity method showYuv.
private void showYuv(byte[] yuvData) {
Allocation bmData = null;
bmData = renderScriptNV21ToRGBA888(this, stride, scanline, yuvData);
Bitmap stitchBmp = Bitmap.createBitmap(stride, scanline, Bitmap.Config.ARGB_8888);
bmData.copyTo(stitchBmp);
// stitchBmp = getRotatedImage(stitchBmp, 90);
final Bitmap finalStitchBmp = stitchBmp;
runOnUiThread(new Runnable() {
@Override
public void run() {
imageView.setImageBitmap(finalStitchBmp);
}
});
}
use of android.renderscript.Allocation in project vlc-android by GeoffreyMetais.
the class UiTools method blurBitmap.
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blurBitmap(Bitmap bitmap, float radius) {
if (bitmap == null || bitmap.getConfig() == null)
return null;
// 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.Config.ARGB_8888);
// Instantiate a new Renderscript
RenderScript rs = RenderScript.create(VLCApplication.getAppContext());
// 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
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);
// After finishing everything, we destroy the Renderscript.
rs.destroy();
return outBitmap;
}
Aggregations