gpt4 book ai didi

Android 创建具有 3 个圆角和 1 个直角的 ImageView

转载 作者:行者123 更新时间:2023-11-29 18:30:46 25 4
gpt4 key购买 nike

我想创建一个有 3 个圆角和一个直角的 ImageView 。

设置背景可绘制不起作用,我确实找到了一些 java 代码,但它只圆了 2 个角或 4 个而不是 3 个

Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);

final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(),
bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;

paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

paint.setXfermode(new
PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);

return output;

The resultant image should be as attached

最佳答案

那里有写得很好的库,这样你就可以将图像剪切到你想要的任何路径,但这里是代码:

private Bitmap clip(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);

final Paint paint = new Paint();
paint.setAntiAlias(true);


// creating a closing path with 3 rounded corners
Path path = new Path();
float radius = 48;
float diameter = radius * 2;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
path.addArc(0, 0, diameter, diameter, 180, 90);
path.lineTo(width - radius, 0);
path.arcTo(width - diameter, 0, width, diameter, 270, 90, false);
path.lineTo(width, height);
path.lineTo(radius, height);
path.arcTo(0, height - diameter, diameter, height, 90, 90, false);
path.close();


paint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
canvas.drawPath(path, paint);

return output;

}

关于Android 创建具有 3 个圆角和 1 个直角的 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56425784/

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