gpt4 book ai didi

Android:单击按钮时模糊屏幕

转载 作者:行者123 更新时间:2023-11-30 01:51:15 25 4
gpt4 key购买 nike

我一直在努力寻找解决这个问题的方法。我有一个包含多个按钮和布局以及一组按钮的 Activity ,比如 btnA、btnB、btnC。现在单击 btnA,我想散焦或模糊整个屏幕,除了那组按钮 btnA、btnB、btnC。可能吗?

我试图更改所有布局的 alpha 值,但它不起作用。

最佳答案

Integrate the RenderScript Support Library

然后添加这个类来模糊出需要的图像。

public class BlurBuilder {
private static final float BITMAP_SCALE = 0.4f;
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;
}}

然后将此代码添加到您的 btnA 的 clickListner 并将您的图像传递给它。

   Bitmap blurredBitmap = BlurBuilder.blur( getActivity(), originalBitmap );
view.setBackgroundDrawable( new BitmapDrawable( getResources(), blurredBitmap ) );

关于Android:单击按钮时模糊屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com