Tôi đang cố gắng tạo phần dưới cùng của Làm mờ hình ảnh cho chế độ xem ở trên cùng như trong hình ảnh.Chế độ xem Blur Android (Nền mờ phía sau chế độ xem)
Tôi đã thử làm mờ nó bằng cách sử dụng Rendenscript nhưng tôi không thể chỉ làm mờ phần phía sau chế độ xem. :(
Tôi đã thấy nhiều thư viện nhưng hầu như tất cả trong số họ làm mờ toàn bộ hình ảnh, nhưng không phải là một phần của nó.
Ngoài ra, một phần quan trọng là tôi đang sử dụng này bên trong một ViewPager và do đó cần phải . được nhanh chóng và năng động giống như this in IOS mà vẽ lại bản thân hình ảnh khoảnh khắc đằng sau nó thay đổi
Any help is appreciated Cảm ơn đã dừng lại do
xml của tôi:.!
<?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>
Mã của tôi:
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();
}
}
Trong onCreate MainActivity tôi tôi làm:
BlurBuilder.blur(BitmapActivity.this, ((BitmapDrawable) mView.getDrawable()).getBitmap(), mDummyView);
Dưới đây là kết quả:
Bạn có thể sử dụng [FastBlur] (http://trickyandroid.com/ tiên tiến-blurring-kỹ thuật /) –
Có lẽ mờ trong suốt trên xem dưới cùng của bạn sẽ làm các trick. – NullByte
@NullByte thích? –