Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday, 17 February 2016

How to image blur

Hello gyes
If you want to your imageview image blur then follow my blog sample..

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background=“#e5e5e5”
    android:orientation="vertical">

 
                <ImageView
                    android:id="@+id/holder"
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/img_header"
                    android:tint="#11000000" />


</LinearLayout>


MainActivity.java

/*
*
*Samset created 17/02/2016
*/
public class MainActivity extends AppCompatActivity {
private ImageView placeholder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
 placeholder= (ImageView) findViewById(R.id.holder);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.img_header);
Bitmap blurredBitmap = blur(bitmap);
placeholder.setImageBitmap(blurredBitmap);


       
    }
//by samset
public Bitmap blur(Bitmap image) {
    if (null == image) return null;

    Bitmap outputBitmap = Bitmap.createBitmap(image);
    final RenderScript renderScript = RenderScript.create(this);
    Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
    Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);

   
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);
    }

    return outputBitmap;
}


}

I hope this sample helps you

Thank you 





No comments:

Post a Comment