Bitmap U8_4Bitmap; if(sentBitmap.getConfig() == Bitmap.Config.ARGB_8888) { U8_4Bitmap = sentBitmap; } else { U8_4Bitmap = sentBitmap.copy(Bitmap.Config.ARGB_8888, true); } //============================== Bitmap bitmap = Bitmap.createBitmap(U8_4Bitmap.getWidth(), U8_4Bitmap.getHeight(), U8_4Bitmap.getConfig()); final RenderScript rs = RenderScript.create(context); final Allocation input = Allocation.createFromBitmap(rs, U8_4Bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT); final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, output.getElement()); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(bitmap); rs.destroy(); return bitmap;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void blur(Bitmap bkg, View view) { long startMs = System.currentTimeMillis(); float radius = 10; Bitmap overlay = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft(), -view.getTop()); canvas.drawBitmap(bkg, 0, 0, null); RenderScript rs = RenderScript.create(this); Allocation allocation = Allocation.createFromBitmap(rs, overlay); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, allocation.getElement()); blur.setInput(allocation); blur.setRadius(radius); blur.forEach(allocation); allocation.copyTo(overlay); view.setBackground(new BitmapDrawable(getResources(), overlay)); rs.destroy(); StopWatch.log(System.currentTimeMillis() - startMs + "ms"); }
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 + ""); }
@Override public void computeFeatureMap() { int n = inputShape[0][0]; int h = inputShape[0][1]; int w = inputShape[0][2]; int c = inputShape[0][3]; int channelAligned = getInputChannelAligned(); FeatureMap input = (FeatureMap) featureMapInput[0]; Allocation inAllocation = input.getFeatureMap(); if(inAllocation.getElement().getVectorSize()==4){ softmaxScript.set_channelAligned(channelAligned); } else{ softmaxScript.set_channelAligned(c); } softmaxScript.set_inBlob(inAllocation); Script.LaunchOptions option = new Script.LaunchOptions(); option.setX(0, n * h * w * c); softmaxScript.forEach_compute_exp(option); option.setX(0, n * h * w); softmaxScript.forEach_compute_exp_sum(option); option.setX(0, n * h * w * c); softmaxScript.forEach_compute(option); featureMapOutput = featureMapInput[0]; }