android+壁纸模糊,android中imageview背景图像的模糊处理

博客展示了在Android中实现壁纸模糊效果的代码。包含XML布局设置图片的宽高、缩放类型等属性,以及Java代码中对图片进行解码、模糊处理并显示在ImageView上,使用RenderScript和ScriptIntrinsicBlur实现高斯模糊。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

试试看--->>

XML

android:layout_width="match_parent"

android:layout_height="400dp"

xmlns:android="http://schemas.android.com/apk/res/android">

android:scaleType="centerCrop" // scaletype depends upon image you adjust or dont put

android:id="@+id/customProfileGridImg"

android:layout_width="match_parent"

android:layout_height="400dp"

/>

android:layout_width="match_parent"

android:layout_height="500dp"

android:scaleType="centerCrop" // scaletype depends upon image you adjust or dont put

android:src="@drawable/nature"

android:layout_centerInParent="true"/>

-->

public class MainActivity extends AppCompatActivity {

private static final float BLUR_RADIUS = 25f;

ImageView imageView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.mjhgf);

imageView = (ImageView) findViewById(R.id.customProfileGridImg);

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.nature);

Bitmap blurredBitmap = blur(bitmap);

imageView.setImageBitmap(blurredBitmap);

}

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);

//Intrinsic Gausian blur filter

ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));

theIntrinsic.setRadius(BLUR_RADIUS);

theIntrinsic.setInput(tmpIn);

theIntrinsic.forEach(tmpOut);

tmpOut.copyTo(outputBitmap);

return outputBitmap;

}

}

X4EYy.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值