no german umlaute with function "ShowTextAtPoint" in CGBitmapContext
we have a problem displaying text with german umlaute with the function ShowTextAtPoint
in CGBitmapContext
. The umlaute characters are not displayed.
We tried to convert Code from XCode:
CGContextSelectFont(MyBitmapContext, FontName, 24, kCGEncodingMacRoman);
CGContextShowTextAtPoint(MyBitmapContext, x, y, [caption cStringUsingEncoding:
NSMacOSRomanStringEncoding], [caption length]);
开发者_Python百科to MonoTouch:
MyBitmapContext.SelectFont(FontName, 24, CGTextEncoding.MacRoman);
MyBitmapContext.ShowTextAtPoint(x, x, caption , caption.Length);
Thanks a lot for any help.
Frank
The problem is that CoreGraphics APIs for CGContext do not support rendering UTF8 code, it is limited to the text encoding in MacRoman (as you showed in your sample).
The fix is to use the UIKit functions instead, to do this, you can change your code to be like this:
UIGraphics.PushContext (mBmpContext);
mBmpContext.SetRGBFillColor(1f,1f,1f,1f);
var font = UIFont.FromName ("Arial", 30);
using (var nsstr = new NSString ("äöü ÜÖÄ")){
nsstr.DrawString (new PointF (10, 400), font);
}
UIGraphics.PopContext ()
精彩评论