no german umlaute in CGBitmapContext

2019-03-06 01:39发布

问题:

we have a problem with displaing text with german umlaute with the function "ShowTextAtPoint" in CGBitmapContext. The umlaute characters are not displayed. Has anybody an idea for any workaround?

thanks for an answer, Frank

回答1:

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 ()


回答2:

You can also use escape sequences to get it to work:

see this page for the characters you want: http://en.wikipedia.org/wiki/Mac_OS_Roman

"\x80, \xE8, \xEC, \x85, \x86" will give the capital vowels in order: A, E, I, O, U with umlaute

"\x8A, \x91, \x95, \x9A, \x9F" will give the lowercase vowels in order: a, e, i, o, u with umlaute

MacRoman includes the characters you were needing, so you don't need to use UIKit if you prefer to work in CoreGraphics.



标签: xamarin.ios