现在,我在Xamarin Android上使用SkiaSharp.
我想用SKCanvas.DrawText绘制日语文本,但是日语字符乱码.
我看见了这个
similar question,所以我尝试将文本转换为UTF-8,但是结果是相同的.
我尝试如下.
var s = "abcあいう123壱弐参";var buf = System.Text.EnCoding.UTF8.GetBytes(s);var utf8s = EnCoding.UTF8.GetString(buf);skcanvas.DrawText(utf8s, 50, 50, paint);
另一个.
var s = "abcあいう123壱弐参";var dest = EnCoding.UTF8;var src = EnCoding.Default;var buf = src.GetBytes(s);var buf2 = EnCoding.Convert(src,dest, buf);var utf8s = dest.GetString(buf2);skcanvas.DrawText(utf8s, 50, 50, paint);
两者的结果是相同的.很好地绘制了“ abc”和“ 123”,但是日语字符显示为乱码.
任何想法?
解决方法:
假设您正在加载一种自定义字体(如Uzumasa Honmaru Gothic),则可以将其添加到每个本机平台项目中,然后通过该本机项目或基于Xamarin.Forms的项目使用它:
AndroID:
string Fontname = "UzumasaFontMini.otf";string FontPath = Path.Combine (CacheDir.absolutePath, Fontname);using (var asset = Assets.Open (Fontname))using (var dest = file.Open (FontPath, fileMode.Create)) { asset.copyTo (dest);}string customFontPath = FontPath;
iOS:
string Fontname = "UzumasaFontMini.otf";string customFontPath = NSBundle.MainBundle.PathForResource (Path.GetfilenameWithoutExtension (Fontname), Path.GetExtension (Fontname));
DrawText:
string text = "abcあいう123";using (var paint = new SKPaint ()) { canvas.Clear (SKcolors.Black); paint.IsAntialias = true; using (var tf = SKTypeface.Fromfile (customFontPath)) { paint.color = SKcolors.White; paint.TextSize = 20; paint.Typeface = tf; canvas.DrawText (text, 50, 50, paint); }}
AndroID:
iOS:
总结以上是内存溢出为你收集整理的android-如何在Xamarin上用SkiaSharp绘制日语文本全部内容,希望文章能够帮你解决android-如何在Xamarin上用SkiaSharp绘制日语文本所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)