Make ImageView Circular

本文关键字:Circular ImageView Make | 更新日期: 2023-09-27 18:09:48

我有一个ImageView,我试图在Xamarin中制作圆形。这将是足够简单,我将做它与核心动画,但图像是异步下载,像这样:

this.profileImage.InvokeOnMainThread (() => this.profileImage.SetImage (
    url: new NSUrl (datum.user.profile_picture)
    )
); 

我如何使这些图像圆形?

Make ImageView Circular

这就是我如何解决我的问题:

this.profileImage.InvokeOnMainThread (() => this.profileImage.SetImage (
            url: new NSUrl (datum.user.profile_picture)
        )
    );
// Make Image Profile Image Circular
CALayer profileImageCircle = profileImage.Layer;
profileImageCircle.CornerRadius = 30;
profileImageCircle.MasksToBounds = true;

紧随其后-迟到但可能有所帮助

**使用OP的代码使应用程序更通用,以制作任何图像-无论大小,圆形**

this.profileImage.InvokeOnMainThread (() => this.profileImage.SetImage (
            url: new NSUrl (datum.user.profile_picture)
        )
    );
// Make Image Profile Image Circular
CALayer profileImageCircle = profileImage.Layer;
profileImageCircle.CornerRadius = profileImageCircle.Frame.Size.Width / 2;
profileImageCircle.MasksToBounds = true;

通过添加profileimageccircle . frame . size。Width/2;"我们将得到我们正在使用的图像所需的半径,因此它将始终是圆形的-假设它是一个方形图像。

imageView.Layer.CornerRadius = imageView.Frame.Size.Width / 2;
imageView.ClipsToBounds = true;