Blur Bitmap Image - Android Graphics

Android examples for Graphics:Bitmap Blur

Description

Blur Bitmap Image

Demo Code


//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;

import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;

public class Main {
    public static Bitmap BlurImage(Bitmap bm, Context context, float radius) {
        //Assuming my original Bitmap is "bm"
        Bitmap outputBitmap = Bitmap.createBitmap(bm.getWidth(),
                bm.getHeight(), Bitmap.Config.ARGB_8888);

        RenderScript rs = RenderScript.create(context);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs,
                Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, bm);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(radius);/* www.  j  a v a2s  .  c  om*/
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);
        bm.recycle();
        rs.destroy();

        return outputBitmap;
    }
}

Related Tutorials