Forum Cross Platform with Xamarin

How to create Rounded image in xamarin.froms by monotouch code?


I've a code that convert image in round shape, I need to use in Xamarin.Forms

public static UIImage GetRoundImage (UIImage im) { if (im == null) return null; UIGraphics.BeginImageContextWithOptions (new SizeF(im.Size.Width/2, im.Size.Height/2), false, 0); UIBezierPath.FromRoundedRect ( new RectangleF (0, 0, im.Size.Width/2, im.Size.Height/2), im.Size.Width / 2 ).AddClip(); im.Draw (new RectangleF (0, 0, im.Size.Width/2, im.Size.Height/2)); UIImage im1 = UIGraphics.GetImageFromCurrentImageContext (); UIGraphics.EndImageContext (); return im1; }

I tried to use with dependency service by taking reference of this URL

Can anybody tell me how can i do this and what are the steps I've to use to get Rounded Image in Xamarin.Forms ?


  • adamkempadamkemp USInsider, Developer Group Leader mod

    Rather than changing the image you can just use a custom renderer that displays the image with a circular clip by using the layer's CornerRadius property. @JasonSmith‌ showed how to do this in just a small bit of code in his Evolve talk. Maybe he can point you to the code.

  • Thanks... for the suggestion... Did you use somewhere in forms ?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I haven't done this myself personally, but it can be done. You just create a custom element derived from Image with a custom renderer derived from ImageRenderer, and in that custom renderer you would use CornerRadius to get the round effect. See this similar post:

Sign In or Register to comment.