android背景进行高斯模糊

本文记录了在Android中实现Dialog背景高斯模糊的思路和步骤,包括截屏、模糊处理和设置为Dialog背景。然而,由于性能问题在某些设备上可能会出现掉帧,因此被弃用,但仍然有其参考价值。
摘要由CSDN通过智能技术生成

前言

写这个东西主要是想把这个东西记下来,根据实际使用的情况来看,有些分辨率高的手机进行模糊所花费的时间有点长,使用动画进行掩饰后,发现这个方法可能在不同的手机上有掉帧的情况,进行高斯模糊的性能比较低,最后被同事弃用,但是我觉得弃之可惜,毕竟一种方法总有可取之处,特此记录下来。


实现思路

1. 对背景屏幕进行截屏

2. 对截屏的图片进行高斯模糊

3. 将进行模糊的图片设置为Dialog的背景

4. 在图片上面覆盖一层布局,这个布局主要的作用就是让最后表现为某某颜色的半透明状态。


代码实现

dialog_blur_bg_layout.xml

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

    <ImageView
        android:id="@+id/iv_blur_show"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"/>

    <ImageView
        android:id="@+id/iv_blur_alpha"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#77000000"/>

    <FrameLayout
        android:id="@+id/fl_add_views"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"/>

</RelativeLayout>


对应的Dialog类为:

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.vi
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值