Java Code Examples for android.support.v8.renderscript.RenderScript#create()

The following examples show how to use android.support.v8.renderscript.RenderScript#create() . 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: BlurBuilder.java    From FlyWoo with Apache License 2.0 6 votes vote down vote up
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);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);


    return outputBitmap;
}
 
Example 2
Source File: RenderscriptBlurringMachine.java    From fogger with Apache License 2.0 6 votes vote down vote up
@Override
protected Bitmap blur(Context context, Bitmap bitmapToBlur, int radius) {
    Log.i(TAG, "Current build version sdk " + Build.VERSION.SDK_INT);
    Bitmap bitmap = bitmapToBlur.copy(bitmapToBlur.getConfig(), true);

    final RenderScript renderScript = RenderScript.create(context, Build.VERSION.SDK_INT);
    final Allocation input = Allocation.createFromBitmap(renderScript, bitmapToBlur,
                                                            Allocation.MipmapControl.MIPMAP_NONE,
                                                            Allocation.USAGE_SCRIPT);
    final Allocation output = Allocation.createTyped(renderScript, input.getType());
    try {
        final ScriptIntrinsicBlur script = createBlurringScript(radius, renderScript, input);
        script.forEach(output);
        renderScript.finish();
        output.copyTo(bitmap);
    } finally {
        input.destroy();
        output.destroy();
        bitmapToBlur.recycle();
        renderScript.destroy();
    }
    return bitmap;
}
 
Example 3
Source File: MizLib.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a blurred bitmap. It uses a RenderScript to blur the bitmap very fast.
 * @param context
 * @param originalBitmap
 * @param radius
 * @return
 */
public static Bitmap fastBlur(Context context, Bitmap originalBitmap, int radius) {
    final RenderScript rs = RenderScript.create(context);

    final Allocation input = Allocation.createFromBitmap(rs, originalBitmap);
    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(originalBitmap);

    return originalBitmap;
}
 
Example 4
Source File: DefaultBlur.java    From ngAndroid with Apache License 2.0 5 votes vote down vote up
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);
    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;
}
 
Example 5
Source File: GlassView.java    From GlassView with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mRenderScript = RenderScript.create(getContext());
    mBlur = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
    if (isPostHoneycomb() && isHardwareAccelerated()) {
        getViewTreeObserver().addOnGlobalLayoutListener(getGlobalLayoutListener());
        getViewTreeObserver().addOnScrollChangedListener(getScrollChangedListener());
    }
}
 
Example 6
Source File: BlendTest.java    From easyrs with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    setContext(context);
    createApplication();
    rs = RenderScript.create(getApplication());
}
 
Example 7
Source File: RenderScriptBlurHelper.java    From BlurDialogFragment with Apache License 2.0 5 votes vote down vote up
/**
 * blur a given bitmap
 *
 * @param sentBitmap       bitmap to blur
 * @param radius           blur radius
 * @param canReuseInBitmap true if bitmap must be reused without blur
 * @param context          used by RenderScript, can be null if RenderScript disabled
 * @return blurred bitmap
 */
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap, Context context) {
    Bitmap bitmap;

    if (canReuseInBitmap) {
        bitmap = sentBitmap;
    } else {
        bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
    }

    if (bitmap.getConfig() == Bitmap.Config.RGB_565) {
        // RenderScript hates RGB_565 so we convert it to ARGB_8888
        // (see http://stackoverflow.com/questions/21563299/
        // defect-of-image-with-scriptintrinsicblur-from-support-library)
        bitmap = convertRGB565toARGB888(bitmap);
    }

    try {
        final RenderScript rs = RenderScript.create(context);
        final Allocation input = Allocation.createFromBitmap(rs, bitmap, 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);
        return bitmap;
    } catch (RSRuntimeException e) {
        Log.e(TAG, "RenderScript known error : https://code.google.com/p/android/issues/detail?id=71347 "
            + "continue with the FastBlur approach.");
    }

    return null;
}
 
Example 8
Source File: HistogramTest.java    From easyrs with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    setContext(context);
    createApplication();
    rs = RenderScript.create(getApplication());
}
 
Example 9
Source File: BlurTransformation.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
@Override
    public Bitmap transform(Bitmap source) {
        Timber.i("start bitmap transform");
        try {
            float radius = 10f;
            Bitmap outputBitmap;
//            if(Build.VERSION.SDK_INT >= 17){
                outputBitmap = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
                RenderScript rs = RenderScript.create(ctx);
                ScriptIntrinsicBlur sib = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
                Allocation tmpIn = Allocation.createFromBitmap(rs, source);
                Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
                sib.setRadius(radius);
                sib.setInput(tmpIn);
                sib.forEach(tmpOut);
                tmpOut.copyTo(outputBitmap);
                source.recycle();
//            }else{
//                outputBitmap = FastBlur.doBlur(source, (int) radius, true);
//            }
            Timber.d("blur bitmap success");
            return outputBitmap;
        } catch (Exception e) {
            Timber.e(e, "occur an error during blurring bitmap");
            return source;
        }
    }
 
Example 10
Source File: BlurTest.java    From easyrs with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    setContext(context);
    createApplication();
    rs = RenderScript.create(getApplication());
}
 
Example 11
Source File: RSGaussian5x5BlurProcessor.java    From BlurView with Apache License 2.0 4 votes vote down vote up
private RSGaussian5x5BlurProcessor(Context context) {
    mRSGaussian5x5Blur = new RSGaussian5x5Blur(RenderScript.create(context));
}
 
Example 12
Source File: RSBlurProcess.java    From BlurView with Apache License 2.0 4 votes vote down vote up
public RSBlurProcess(Context context) {
	this.context = context.getApplicationContext();
	_rs = RenderScript.create(this.context);
}
 
Example 13
Source File: BlurTransformation.java    From android-tutorials-glide with MIT License 4 votes vote down vote up
public BlurTransformation(Context context) {
    super(context);

    rs = RenderScript.create(context);
}
 
Example 14
Source File: BlurringView.java    From BlurredGridMenu with Apache License 2.0 4 votes vote down vote up
private void initializeRenderScript(Context context) {
    mRenderScript = RenderScript.create(context);
    mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
}
 
Example 15
Source File: GBlurPic.java    From AndroidGaussianBlur with MIT License 4 votes vote down vote up
public GBlurPic(Context context) {
	super();
	this.mRS = RenderScript.create(context);
	this.mBlur = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
}
 
Example 16
Source File: MainActivity.java    From ImageCropRotateFilter with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBitmapIn = loadBitmap(R.drawable.myfilter);
    // mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(), mBitmapIn.getConfig());
    mBitmapOut = mBitmapIn.copy(mBitmapIn.getConfig(), true);
    mRS = RenderScript.create(this);
    mInPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapIn);
    mOutPixelsAllocation = Allocation.createFromBitmap(mRS, mBitmapOut);

    mOriginalDisplayView = (ImageView) findViewById(R.id.original_display);
    mCropDisplayView = (CropImageView) findViewById(R.id.crop_display);
    mCropListView = (HorizontalScrollView) findViewById(R.id.crop_list);
    mCropCancel = (Button) findViewById(R.id.crop_cancel);
    mCropOK = (Button) findViewById(R.id.crop_ok);
    mRotateListView = (HorizontalScrollView) findViewById(R.id.rotate_list);
    mRotateCW = (Button) findViewById(R.id.rotate_cw);
    mRotateCCW = (Button) findViewById(R.id.rotate_ccw);
    mFilterListView = (HorizontalScrollView) findViewById(R.id.filter_list);
    mFilterBW = (Button) findViewById(R.id.filter_bw);
    mFilterBlur = (Button) findViewById(R.id.filter_blur);
    mFilterOriginal = (Button) findViewById(R.id.filter_original);
    mClipBtn = (Button) findViewById(R.id.clip);
    mRotateBtn = (Button) findViewById(R.id.rotate);
    mFilterBtn = (Button) findViewById(R.id.filter);
    mFilterBar1 = (SeekBar) findViewById(R.id.filter_bar1);

    mOriginalDisplayView.setImageBitmap(mBitmapOut);
    mCropCancel.setOnClickListener(mOnClickListener);
    mCropOK.setOnClickListener(mOnClickListener);
    mRotateCW.setOnClickListener(mOnClickListener);
    mRotateCCW.setOnClickListener(mOnClickListener);
    mFilterBW.setOnClickListener(mOnClickListener);
    mFilterBlur.setOnClickListener(mOnClickListener);
    mFilterOriginal.setOnClickListener(mOnClickListener);
    mClipBtn.setOnClickListener(mOnClickListener);
    mRotateBtn.setOnClickListener(mOnClickListener);
    mFilterBtn.setOnClickListener(mOnClickListener);
    mFilterBar1.setOnSeekBarChangeListener(mOnSeekBarChangeListener);
}
 
Example 17
Source File: BlurBehindView.java    From BlurView with Apache License 2.0 4 votes vote down vote up
private void initRenderScript(Context context) {
    //RenderScript
    mRenderScript = RenderScript.create(context);
    mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
    blurRadius(blurRadius);
}
 
Example 18
Source File: RSGaussianBlurProcessor.java    From BlurView with Apache License 2.0 4 votes vote down vote up
private RSGaussianBlurProcessor(Context context) {
    mRSGaussianBlur = new RSGaussianBlur(RenderScript.create(context));
}
 
Example 19
Source File: BlurringView.java    From 500px-guideview with Apache License 2.0 4 votes vote down vote up
private void initializeRenderScript(Context context) {
    mRenderScript = RenderScript.create(context);
    mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
}
 
Example 20
Source File: BlurZoomCoordinatorLayout.java    From BlurZoomGallery with MIT License 3 votes vote down vote up
public BlurZoomCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    parseAttrs(attrs);

    renderScript = RenderScript.create(getContext());
}