7
我正在Xamarin開發,並希望繪製一個簡單的圓圈內的文字「CIRCLE」,並在UIImageView中顯示該圖像。問題在於圓圈和文字顯得非常模糊。我讀了一些關於子像素的內容,但我不認爲這是我的問題。iOS繪製一個簡單的圖像變成模糊使用Xamarin C#
這裏的模糊圖像和代碼,希望有人有一些想法:)
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;
像素加倍視網膜是問題,你的建議解決了它。良好的工作,謝謝:) – 2013-04-09 08:54:38