?我想为Windows8应用程序生成图像,我将使用SharpDXAPI这里是代码示例我感谢复制和粘贴privateMemoryStreamRenderStaticTextToBitmap(){varwidth=400;变种高度=100;varpixelFormat=WicPixelFormat.Format32bppBGR;varwicFactory=newImagingFactory();vardddFactory=newSharpDX.Direct2D1.Factory();vardwFactory=newSharpDX.DirectWrite.Factory();varwicBitmap=newBitmap(wicFactory,width,height,pixelFormat,BitmapCreateCacheOption.CacheOnLoad);=newRenderTargetProperties(RenderTargetType.Default,newD2DPixelFormat(Format.Unknown,AlphaMode.Unknown),0,0,RenderTargetUsage.None,FeatureLevel.Level_DEFAULT);varrenderTarget=newWicRenderTarget(dddFactory,wicBitmap,renderTargetProperties){TextAntialiasMode=TextAntialiasMode。清除类型};renderTarget.BeginDraw();vartextFormat=newTextFormat(dwFactory,"Consolas",48){TextAlignment=SharpDX.DirectWrite.TextAlignment.Cen之三,ParagraphAlignment=ParagraphAlignment.Center};vartextBrush=newSharpDX.Direct2D1.SolidColorBrush(renderTarget,SharpDX.Colors.Blue);renderTarget.Clear(Colors.White);renderTarget.DrawText("嗨,妈妈!",textFormat,newRectangleF(0,0,width,height),textBrush);渲染目标.EndDraw();varms=newMemoryStream();varstream=newWICStream(wicFactory,ms);varencoder=newPngBitmapEncoder(wicFactory);.初始化(流);varframeEncoder=newBitmapFrameEncode(编码器);frameEncoder.Initialize();frameEncoder.SetSize(宽度,高度);frameEncoder.PixelFormat=WicPixelFormat.FormatDontCare;frameEncoder.WriteSource(wicBitmap);;编码器.Commit();frameEncoder.Dispose();编码器.Dispose();stream.Dispose();ms.Position=0;返回ms;这适用于安装的字体......我在文件夹中有资产文件字体,我想使用-我有大约604种自定义字体,我动态选择字体,我知道文件夹中有加载文件......帮助请不幸的是,afaik,DirectWrite中没有API可以轻松支持这一点。您需要开发自己的字体加载器和相关类。SharpDX示例CustomFont正在从资源加载字体,因此您可以调整它以从不同的位置加载。以上就是C#学习教程:如何在SharpDX中使用文件字体?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
