gpt4 book ai didi

图像周围带有红色圆形边框的 Android Piccaso

转载 作者:行者123 更新时间:2023-11-29 19:15:12 26 4
gpt4 key购买 nike

我正在使用 Piccaso 库制作圆形图像,但不知何故我无法在图像周围添加红色圆形边框。我正在使用下面的 Tranform 类来做到这一点:

ublic class RedCircleTransform implements Transformation {
int mBorderSize;

@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());

int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;

Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}

Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setStrokeWidth(10);
paint.setColor(Color.RED);
paint.setAntiAlias(true);

float r = size / 2f;
canvas.drawCircle(r, r, r, paint);

squaredBitmap.recycle();
return bitmap;
}

@Override
public String key() {
return "circle";
}
}

最佳答案

您可以通过 Lopez Mikhael 使用 CircularImageView

渐变

compile 'com.mikhaellopez:circularimageview:3.0.2'

XML

<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/image"
app:civ_border_color="#EEEEEE"
app:civ_border_width="4dp"
app:civ_shadow="true"
app:civ_shadow_radius="10"
app:civ_shadow_color="#8BC34A"/>

关于图像周围带有红色圆形边框的 Android Piccaso,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43773492/

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