你大概知道System.Drawing,它是一个执行图形相关任务的流行的API,同时它也不属于.NET Core的一部分。最初是把.NET Core作为云端框架设计的,它不包含非云端相关API。另一方面,.NET Core是跨平台框架,它不包含任何操作系统特定的API,例如Windows上的Active Directory活动目录 。再者,.NET Core也不包括类似,作为.NET framework一部分的,ConfigurationManager这样的诸多API。

在我之前的文章中,我已经描述了如何将这些API用于.NET Core和.NET标准应用程序。

为了实现这一点,有一个称为Windows Compatibility Pack的元包。但是,这个元包包含许多与Windows相关的API(作为包分发)。在这个元包里面有一个System.Drawing.Common包。

为了在.NET Core中使用绘图功能,请在Nuget包添加引用:

<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview1-**" >

在这之后,你将可以运行例如以下的代码。

int x = 100;
Image image = new Bitmap(2000, 1024); Graphics graph = Graphics.FromImage(image); graph.Clear(Color.Azure); Pen pen = new Pen(Brushes.Black); graph.DrawLines(pen, new Point[] { new Point(10,10), new Point(800, 900) }); graph.DrawString("Hello drawing from .NET Core :)",
new Font(new FontFamily("DecoType Thuluth"), 20, FontStyle.Bold),
Brushes.Blue, new PointF(150, 90)); image.Save("graph.jpeg", System.Drawing.Imaging.ImageFormat.Png);

在你运行上述代码之后,你将看到如下图片:

下面是当前已经支持的字体列表:

AGA Arabesque
AGA Arabesque Desktop
Agency FB
Akhbar MT
Algerian
Arial
Arial Black
Arial Narrow
Arial Rounded MT Bold
Bahnschrift
Bahnschrift Light
Bahnschrift SemiBold
Bahnschrift SemiLight
Baskerville Old Face
Bauhaus 93
Bell MT
Berlin Sans FB
Berlin Sans FB Demi
Bernard MT Condensed
Blackadder ITC
Bodoni MT
Bodoni MT Black
Bodoni MT Condensed
Bodoni MT Poster Compressed
Bold Italic Art
Book Antiqua
Bookman Old Style
Bookshelf Symbol 7
Bradley Hand ITC
Britannic Bold
Broadway
Brush Script MT
Calibri
Calibri Light
Californian FB
Calisto MT
Cambria
Cambria Math
Candara
Castellar
Centaur
Century
Century Gothic
Century Schoolbook
Chiller
Colonna MT
Comic Sans MS
Consolas
Constantia
Cooper Black
Copperplate Gothic Bold
Copperplate Gothic Light
Corbel
Courier New
Curlz MT
DecoType Naskh
DecoType Naskh Extensions
DecoType Naskh Special
DecoType Naskh Swashes
DecoType Naskh Variants
DecoType Thuluth
Diwani Bent
Diwani Letter
Diwani Outline Shaded
Diwani Simple Outline
Diwani Simple Outline 2
Diwani Simple Striped
Dosis
Dubai
Dubai Light
Dubai Medium
Ebrima
Edwardian Script ITC
Elephant
Engravers MT
Eras Bold ITC
Eras Demi ITC
Eras Light ITC
Eras Medium ITC
Farsi Simple Bold
Farsi Simple Outline
Felix Titling
Footlight MT Light
Forte
Franklin Gothic Book
Franklin Gothic Demi
Franklin Gothic Demi Cond
Franklin Gothic Heavy
Franklin Gothic Medium
Franklin Gothic Medium Cond
Freestyle Script
French Script MT
FZShuTi
FZYaoTi
Gabriola
Gadugi
Garamond
Georgia
Gigi
Gill Sans MT
Gill Sans MT Condensed
Gill Sans MT Ext Condensed Bold
Gill Sans Ultra Bold
Gill Sans Ultra Bold Condensed
Gloucester MT Extra Condensed
Goudy Old Style
Goudy Stout
Haettenschweiler
Harlow Solid Italic
Harrington
High Tower Text
HoloLens MDL2 Assets
Impact
Imprint MT Shadow
Informal Roman
Italic Outline Art
Javanese Text
Jokerman
Juice ITC
Kristen ITC
Kufi Extended Outline
Kufi Outline Shaded
Kunstler Script
Lato
Lato Black
Led Italic Font
Leelawadee UI
Leelawadee UI Semilight
LiSu
Lucida Bright
Lucida Calligraphy
Lucida Console
Lucida Fax
Lucida Handwriting
Lucida Sans
Lucida Sans Typewriter
Lucida Sans Unicode
Magneto
Maiandra GD
Malgun Gothic
Malgun Gothic Semilight
Marlett
Matura MT Script Capitals
Microsoft Himalaya
Microsoft JhengHei
Microsoft JhengHei Light
Microsoft JhengHei UI
Microsoft JhengHei UI Light
Microsoft New Tai Lue
Microsoft Office Preview Font
Microsoft PhagsPa
Microsoft Sans Serif
Microsoft Tai Le
Microsoft YaHei
Microsoft YaHei Light
Microsoft YaHei UI
Microsoft YaHei UI Light
Microsoft Yi Baiti
MingLiU-ExtB
MingLiU_HKSCS-ExtB
Mistral
Modern No. 20
Mongolian Baiti
Monotype Corsiva
Monotype Koufi
Montserrat
MS Gothic
MS Office Symbol (de-de) Bold
MS Office Symbol (de-de) Light
MS Office Symbol Extralight
MS Office Symbol Regular
MS Office Symbol Semibold
MS Office Symbol Semilight
MS Outlook
MS PGothic
MS Reference Sans Serif
MS Reference Specialty
MS UI Gothic
MT Extra
Mudir MT
MV Boli
Myanmar Text
Niagara Engraved
Niagara Solid
Nirmala UI
Nirmala UI Semilight
NSimSun
OCR A Extended
Old Antic Bold
Old Antic Decorative
Old Antic Outline
Old Antic Outline Shaded
Old English Text MT
Onyx
Oswald
Palace Script MT
Palatino Linotype
Papyrus
Parchment
Perpetua
Perpetua Titling MT
Playbill
PMingLiU-ExtB
Poor Richard
Pristina
PT Bold Arch
PT Bold Broken
PT Bold Dusky
PT Bold Heading
PT Bold Mirror
PT Bold Stars
PT Separated Baloon
PT Simple Bold Ruled
Rage Italic
Ravie
Rockwell
Rockwell Condensed
Rockwell Extra Bold
Script MT Bold
Segoe MDL2 Assets
Segoe Print
Segoe Script
Segoe UI
Segoe UI Black
Segoe UI Emoji
Segoe UI Historic
Segoe UI Light
Segoe UI Semibold
Segoe UI Semilight
Segoe UI Symbol
Showcard Gothic
Simple Bold Jut Out
Simple Indust Outline
Simple Indust Shaded
Simple Outline Pat
SimSun
SimSun-ExtB
Sitka Banner
Sitka Display
Sitka Heading
Sitka Small
Sitka Subheading
Sitka Text
Snap ITC
Source Sans Pro
Source Sans Pro Black
Source Sans Pro Semibold
STCaiyun
Stencil
STFangsong
STHupo
STKaiti
STLiti
STSong
STXihei
STXingkai
STXinwei
STZhongsong
Sylfaen
Symbol
Tahoma
Tempus Sans ITC
Times New Roman
Trebuchet MS
Tw Cen MT
Tw Cen MT Condensed
Tw Cen MT Condensed Extra Bold
Verdana
Viner Hand ITC
Vivaldi
Vladimir Script
Webdings
Wide Latin
Wingdings
Wingdings 2
Wingdings 3
YouYuan
Yu Gothic
Yu Gothic Light
Yu Gothic Medium
Yu Gothic UI
Yu Gothic UI Light
Yu Gothic UI Semibold
Yu Gothic UI Semilight

翻译自:How to use System.Drawing in .NET Core?

[译]如何在.NET Core中使用System.Drawing?的更多相关文章

  1. .netcore中无法使用System.Drawing --解决方案

    问题重现: 无法正常使用  解决方法: 安装System.Drawing.Common的NuGet就能正常使用了 操作之后: 这个是.netcoe中的解决办法,.net framework解决方案中添 ...

  2. [译]如何在Web开发中使用Python

    [译]如何在Web开发中使用Python 原文:HOWTO Use Python in the Web 摘要 这篇文档展示了Python如何融入到web中.它介绍了几种Python结合web服务器的方 ...

  3. 文章翻译:ABP如何在EF core中添加数据过滤器

    原文地址:https://aspnetboilerplate.com/Pages/Documents/Articles%5CHow-To%5Cadd-custom-data-filter-ef-cor ...

  4. [译]在Asp.Net Core 中使用外部登陆(google、微博...)

    原文出自Rui Figueiredo的博文<External Login Providers in ASP.NET Core> 摘要:本文主要介绍了使用外部登陆提供程序登陆的流程,以及身份 ...

  5. .net core中关于System.Text.Json的使用

    在.Net Framework的时候序列化经常使用Newtonsoft.Json插件来使用,而在.Net Core中自带了System.Text.Json,号称性能更好,今天抽空就来捣鼓一下. 使用起 ...

  6. [译]如何在visual studio中调试Javascript

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  7. 在linux 或docker中使用 system.drawing.common

    在dockerfile 中添加 FROM microsoft/dotnet:2.1-aspnetcore-runtime RUN apt-get update RUN apt-get install ...

  8. Linux/Docker 中使用 System.Drawing.Common 踩坑小计

    前言 在项目迁移到 .net core 上面后,我们可以使用 System.Drawing.Common 组件来操作 Image,Bitmap 类型,实现生成验证码.二维码,图片操作等功能.Syste ...

  9. .net core中的System.Buffers名字空间

    最近研究了一下.net core 2.1的基础类库,发现它引入了一个System.Buffers名字空间,里面提供了一系列比较实用的对象,便简单的管中窥豹浏览一下. ArrayPool<T> ...

随机推荐

  1. 《你不知道的JavaScript》三卷读后感

    本系列的作者是Kyle Simpson,上卷译者赵望野.梁杰,中卷译者单业,下卷译者单业.姜南. 我个人觉得第一卷是本系列最好的(必读),而第二卷虽然也讲解了很多知识点,但是对于异步和性能的那部分提及 ...

  2. File(File f, String child) File(String parent, String child)

    (转载)File(File f, String child) 根据f 抽象路径名和 child 路径名字符串创建一个新 File 实例. f抽象路径名用于表示目录,child 路径名字符串用于表示目录 ...

  3. mac 命令行安装软件

    第一步需要在mac上安装brew工具 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mas ...

  4. Python核心团队计划2020年停止支持Python2,NumPy宣布停止支持计划表

    Python核心团队计划在2020年停止支持Python 2.NumPy项目自2010年以来一直支持Python 2和Python 3,并且发现支持Python 2对我们有限的资源增加了负担:因此,我 ...

  5. gii配置

    下载完成后不要设置urlManager http://zjm.testyii.com/index.php?r=gii 即可进入gii页面 或者是 将'urlManager'=> [ 'enabl ...

  6. MySQL优化--INSERT ON DUPLICATE UPDATE死锁

    INSERT ON DUPLICATE UPDATE与死锁 在MySQL中提供两种插入更新的方式:REPLACE INTO和INSERT ON DUPLICATE UPDATE,简化了“存在则更新,不 ...

  7. 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组

    [源码下载] 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组 作者:webabcd 介绍背水一 ...

  8. package-lock.json,我们应该了解

    原谅我占2017年12月31日一个坑,后续补上

  9. Day7:html和css

    Day7:html和css 如果有浮动,会导致脱标,定位也能脱标,我们没有清除浮动,因为里面有子绝父相. 清除浮动的方法 额外标签法,在最后一个浮动元素后面添加一个空的标签代码: <div st ...

  10. Metasploit Framework(7)客户端渗透(下)

    文章的格式也许不是很好看,也没有什么合理的顺序 完全是想到什么写一些什么,但各个方面都涵盖到了 能耐下心看的朋友欢迎一起学习,大牛和杠精们请绕道 应用场景: Kali机器IP:192.168.163. ...