no german umlaute in CGBitmapContext

2019-03-06 00:47发布

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

标签: xamarin.ios
2条回答
Explosion°爆炸
2楼-- · 2019-03-06 01:23

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 ()
查看更多
我命由我不由天
3楼-- · 2019-03-06 01:47

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.

查看更多
登录 后发表回答