Android实现圆形头像
Android中的ImageView只能显示矩形的图片,为了用户体验更多,Android需要实现圆角图像,如图:
为了实现圆角头像,可以按照下述思路来进行:
- 将要上传为头像的图形转换为正方形,这很重要!!!(其实是为了避免麻烦嘿,不是正方形拉伸会很丑的)。
public static Bitmap makeBitmapSquare(Bitmap oldbitmap, int newWidth){
Bitmap newbitmap=null;
if (oldbitmap.getWidth()>oldbitmap.getHeight()){
newbitmap=Bitmap.createBitmap(oldbitmap,oldbitmap.getWidth()/2-oldbitmap.getHeight()/2,0,oldbitmap.getHeight(),oldbitmap.getHeight());
}