【发布时间】:2013-03-31 04:21:28
【问题描述】:
我正在 Xamarin 中进行开发,并想在其中绘制一个带有文本“CIRCLE”的简单圆圈,并在 UIImageView 中显示该图像。问题是圆圈和文字显得非常模糊。我读过一些关于亚像素的文章,但我认为这不是我的问题。
这是模糊的图像和代码,希望有人有一些想法:)
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;
【问题讨论】:
标签: ios xamarin.ios blurry uigraphicscontext