Android Flou de Vue (Flou d'arrière-plan de la vue)

Je suis en train de faire la partie inférieure du flou de l'Image pour l'afficher sur le dessus comme dans l'image.

J'ai essayé de flou à l'aide de Rendenscript mais je ne suis pas en mesure de rendre flou une partie seulement de la vue. 🙁

J'ai vu beaucoup de bibliothèques, mais presque tous le flou de l'image entière, mais pas une partie.

Aussi, une partie importante est que je suis en utilisant ce à l'intérieur d'un ViewPager et doit donc être rapide et dynamique, quelque chose comme présent dans IOS qui se redessine l'instant de l'image derrière elle change.

Toute aide est appréciée. Merci pour s'arrêter par!

Mon xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/image"
        android:src="@drawable/broadstairs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:layout_centerInParent="true"/>

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="Hello World"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:textSize="36sp"/>
</RelativeLayout>

Mon code:

BlurBuilder.java

public class BlurBuilder {
private static final float BITMAP_SCALE = 0.1f;
private static final float BLUR_RADIUS = 7.5f;
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;
}
@SuppressLint("NewApi")
public static void blur(final Context context, final Bitmap bitmap, final View view) {
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... params) {
Paint paint = new Paint();
paint.setFilterBitmap(true);
Bitmap cropImage = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() - view.getHeight(), bitmap.getWidth(), view.getHeight());
return BlurBuilder.blur(context, cropImage);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (bitmap != null) {
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), bitmap));
} else {
view.setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
}
}
}.execute();
}
}

Dans mon MainActivity du onCreate je fais:

BlurBuilder.blur(BitmapActivity.this, ((BitmapDrawable) mView.getDrawable()).getBitmap(), mDummyView);

Ci-dessous est le résultat:

Android Flou de Vue (Flou d'arrière-plan de la vue)

Vous pouvez utiliser FastBlur
Peut-être transparent flou sur votre vue de dessous fera l'affaire.
comme?
Je ne sais pas pourquoi, j'ai essayé FastBlur leur échantillon apk fonctionne parfaitement, mais lorsque je mets en place, je les reçois le flou de la totalité de l'image 🙁
Oui. Il suffit d'appliquer le flou de la background image. Ne pas le src. android:src travaux sur le "premier plan" de l'image. android:background fonctionne sur le fond. Il y a la Java équivalents: setDrawable() et setBackgroundDrawable() - respectivement, depuis que vous avez à faire le tour de votre code. Vous pourriez avoir à désactiver l'accélération matérielle.

OriginalL'auteur Atul O Holic | 2015-08-04