XML code ...
We can take ImageView also.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
<LinearLayout
android:id="@+id/blurimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.widget.LinearLayout;
@SuppressLint("NewApi")
public class BlurImage extends BaseAct{
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blur_image);
temp();
context=this;
LinearLayout blurimage = (LinearLayout)findViewById(R.id.blurimage);
Bitmap blurimages = BlurImage(((BitmapDrawable)getResources().getDrawable(R.drawable.golden_gate)).getBitmap());
blurimage.setBackground(new BitmapDrawable(blurimages));
}
@SuppressLint({"NewApi","NewApi","NewApi","NewApi","NewApi","NewApi","NewApi"})
public Bitmap BlurImage (Bitmap input)
{
RenderScript rsScript = RenderScript.create(context) ;
Allocation alloc = Allocation.createFromBitmap(rsScript, input);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rsScript, Element.U8_4(rsScript));
blur.setRadius(25);
blur.setInput(alloc);
Bitmap result = Bitmap.createBitmap(input.getWidth(), input.getHeight(), input.getConfig());
Allocation outAlloc = Allocation.createFromBitmap(rsScript, result);
blur.forEach(outAlloc);
outAlloc.copyTo(result);
rsScript.destroy();
return result;
}
}
No comments:
Post a Comment