gpt4 book ai didi

android - 圆形快速联系徽章

转载 作者:行者123 更新时间:2023-11-29 17:44:40 25 4
gpt4 key购买 nike

大家好,我有一个带有快速联系人徽章的联系人 ListView 。它显示方形图像,但我的要求是显示圆形快速联系人徽章(如下面的屏幕截图)。请让我知道我怎样才能做到这一点。提前致谢。 enter image description here

最佳答案

以下是创建圆形图像的两种方法。您只需传递位图图像使其成为圆形。

/**
* To make image in a round shape. Use this method if you want to specify required height and width
*
* @param i
*/
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int i) {
int targetWidth = i;
int targetHeight = i;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(((float) targetWidth - 1) / 2,
((float) targetHeight - 1) / 2,
(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
Path.Direction.CCW);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()), new Rect(0, 0, targetWidth,
targetHeight), null);
return targetBitmap;
}

/**
* To make image in a round shape
*/

public static Bitmap getCroppedBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), 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());

paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
// canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
bitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
// Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
// return _bmp;
return output;
}

关于android - 圆形快速联系徽章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27437682/

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