IOS image of a simple image is blurry using Xamarin C #

I am developing at Xamarin and would like to draw a simple circle with the text β€œCIRCLE” inside it and display this image in a UIImageView. The problem is that the circle and the text look very blurry. I read a little about subpixels, but I don't think this is my problem.

Here's a blurry image and code, hoping someone has some ideas :)

UIGraphics.BeginImageContext (new SizeF(150,150)); var context = UIGraphics.GetCurrentContext (); var content = "CIRCLE"; var font = UIFont.SystemFontOfSize (16); const float width = 150; const float height = 150; context.SetFillColorWithColor (UIColor.Red.CGColor); context.FillEllipseInRect (new RectangleF (0, 0, width, height)); var contentString = new NSString (content); var contentSize = contentString.StringSize (font); var rect = new RectangleF (0, ((height - contentSize.Height) / 2) + 0, width, contentSize.Height); context.SetFillColorWithColor (UIColor.White.CGColor); new NSString (content).DrawString (rect, font, UILineBreakMode.WordWrap, UITextAlignment.Center); var image = UIGraphics.GetImageFromCurrentImageContext (); imageView.Image = image; 

Blurry circle

+7
source share
1 answer

The reason it is blurry is because it has been changed. This bitmap is not 150x150 (for example, the context you created), it is 333x317 pixels.

This may be because imageView scales the image (no source code) or because of the doubling of pixels (to display the retina). In the latter case, you really want to use:

 UIGraphics.BeginImageContextWithOptions (size, false, 0); 

which (using 0 ) automatically uses the correct scaling factor to display the retina (or not) - and looks crisp (rather than oversized) on all types of devices.

+12
source

All Articles