c# - C# PrivateFontCollection AddFontFile 从相对路径
问题描述
我从根目录的这个文件夹中有 OpenSans-Light.ttf:~/fonts/open-sans/OpenSans-Light.ttf
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile("~/fonts/open-sans/OpenSans-Light.ttf");
但我得到“System.IO.FileNotFoundException:找不到文件”
如何定位该字体文件?
解决方案
我找到了使用 MapPath 的解决方案:
PrivateFontCollection privateFontCollection = new PrivateFontCollection();
privateFontCollection.AddFontFile(HttpContext.Current.Server.MapPath("~/fonts/open-sans/OpenSans-Light.ttf"));
推荐阅读
- jenkins - 在詹金斯拉取请求构建器作业中获取源分支名称的正确方法是什么
- c - 如何删除一个数组结构,并且最后一个索引不能被其他索引替换?
- c# - Oxyplot Lineannotation 不显示
- google-cloud-platform - CloudBuild 触发器:解组构建配置 cloudbuild.yaml 失败:json:无法将字符串解组为 []json.RawMessage 类型的 Go 值
- php - Laravel save not 无法正常工作,数据库未更新
- java - 使用 Hashmap 查找人均数据
- html - HTML中单个a href链接中的多种样式
- python - python - 如何获得对消息做出反应的不和谐用户?
- reactjs - 历史在 Reactjs 中未定义
- python - PostgreSQL - 更新复合类型数组的一个元素