Java 为什么我不能为ImageView设置圆角?
我正在制作一个发射器,我想让码头看起来像这样: 正如您所见,dock有两个主要功能 1) 高斯模糊 2) 圆角 对于圆角,我使用以下代码:Java 为什么我不能为ImageView设置圆角?,java,android,gaussian,rounded-corners,Java,Android,Gaussian,Rounded Corners,我正在制作一个发射器,我想让码头看起来像这样: 正如您所见,dock有两个主要功能 1) 高斯模糊 2) 圆角 对于圆角,我使用以下代码: RoundedBitmapDrawable RBD = RoundedBitmapDrawableFactory.create(getResources(), bmp); RBD.setCornerRadius(40.0f); RBD.setAntiAlias(true); 其中,bmp是图像的底部部分(我通过编程进行了裁剪) 对于高斯模糊,我使用了
RoundedBitmapDrawable RBD = RoundedBitmapDrawableFactory.create(getResources(), bmp);
RBD.setCornerRadius(40.0f);
RBD.setAntiAlias(true);
其中,bmp是图像的底部部分(我通过编程进行了裁剪)
对于高斯模糊,我使用了API
GaussianBlur.with(this).size(80).radius(25).put(croppedDrawable, dock);
其中,croppedDrawable可绘制图像底部的裁剪位图
以下是完整的代码:
//Cropping image to fit the dimensions of the dock
bmp.setDensity(Bitmap.DENSITY_NONE);
bmp = Bitmap.createBitmap(bmp, 0, (int) dock.getY(), Resources.getSystem().getDisplayMetrics().widthPixels, dock.getHeight());
//Rounded Corners
RoundedBitmapDrawable RBD = RoundedBitmapDrawableFactory.create(getResources(), bmp);
//The radius of corners
RBD.setCornerRadius(40.0f);
//I have no idea why this is used
RBD.setAntiAlias(true);
//Now that the image has roundedCorners, Gaussian blur can be applied
//For this, I have to convert RBD to a drawable. It cannot be cast
//directly, hence, I am first converting it to a bitmap and then to
//a drawable
Bitmap bmp2 = RBD.getBitmap();
Drawable croppedGaussianDrawable = new BitmapDrawable(getResources(), bmp2);
GaussianBlur.with(this).size(80).radius(25).put(croppedGaussianDrawable, dock);
出现问题,因为我得到的输出是:
只有高斯模糊已应用于dock。
我不知道是什么错误。我试过用其他方法,但没有用
有人能告诉我代码有什么问题吗?我哪里做错了?为什么dock图像的角不圆角?RoundedBitmapDrawable#getBitmap()
不会返回圆角的位图。它只返回背景位图
。在内部,将使用该位图创建一个着色器,以进行圆角绘制。在传递RoundedBitmapDrawable
位图之前,需要对其进行模糊处理。