答案 0 :(得分:0)
有一个用于安卓照片的图书馆.... https://github.com/hdodenhof/CircleImageView 这是链接......试试吧:)。
编辑:
或者您可以使用此库:
https://github.com/Pkmmte/CircularImageView
答案 1 :(得分:0)
答案 2 :(得分:0)
您可以使用图标生成器工具(Android Asset Studio)分两步生成圆形图标。
https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html
https://romannurik.github.io/AndroidAssetStudio/icons-actionbar.html
希望这会对你有所帮助。
答案 3 :(得分:0)
答案 4 :(得分:0)
有4个步骤:
<强> 1。创建菜单项
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/profile_menu_item"
android:icon="@drawable/prof"
app:showAsAction="always"
tools:ignore="MenuTitle"/>
</menu>
<强> 2。检索菜单项
private MenuItem mProfileMenuItem;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
mProfileMenuItem = menu.findItem(R.id.profile_menu_item);
return true;
}
第3。将位图裁剪为圆形位图
public 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;
}
<强> 4。将网址图像下载为位图,然后裁剪
new Handler().post(() -> Glide.with(getApplicationContext()).asBitmap().load(url).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
if (mProfileMenuItem == null) return;
mProfileMenuItem.setIcon(new BitmapDrawable(getResources(), Utils.getCroppedBitmap(resource)));
}
}));