flutter 将图片裁剪为圆形

1. 第一种方式,将头像变为圆形格式

//将角度变为圆形
child:Container(
        width: 300,
        height: 300,
        decoration: BoxDecoration(
          color:Colors.yellow,
          borderRadius: BorderRadius.all(
            Radius.circular(20.0)
          ),
          image: DecorationImage(image: NetworkImage("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2692809760,3266574367&fm=26&gp=0.jpg"),
          fit: BoxFit.cover)
        ),
      )

2. 第二种方式

 child: ClipOval(
          child: Image.network(
            'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2692809760,3266574367&fm=26&gp=0.jpg',
            height: 100,
            width: 100,
            fit: BoxFit.cover
          ),
        ),

其中第二种方式可以根据图片尺寸自动适配,推荐第二种

猜你喜欢

转载自blog.csdn.net/caorya/article/details/92796670