Cannot find Bitmap Class in Class Library (.NET Standard)(在类库 (.NET Standard) 中找不到位图类)
问题描述
我想制作一个类库(.NET Standard),我正在使用 System.Drawing,
I want to make a Class Library (.NET Standard) and I'm using System.Drawing,
但我收到错误:
CS0246 C# 找不到类型或命名空间名称位图"(您是否缺少 using 指令或程序集引用?)
CS0246 C# The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)
我使用的是 .NET Standard 2.0.
I'm using .NET Standard 2.0.
推荐答案
更新
截至上个月(2018 年 5 月),Microsoft 发布了 System.Drawing.Common
的生产版本(以前是预览版/RC),这是一个取代 两个版本的 NuGet 包>CoreCompat.System.Drawing
包.这应该在以后使用.
As of last month (May 2018), Microsoft have a production release (previously it was preview/RC) of System.Drawing.Common
, a NuGet package which supersedes both versions of the CoreCompat.System.Drawing
package. This should be used going forwards.
对于那些使用 docker 的人
您还需要在最终 docker 映像中使用 libgdiplus
库,因为 System.Drawing.Common
依赖于此.您可以使用以下 Dockerfile 命令安装它:
You also need the libgdiplus
library within your final docker image, as System.Drawing.Common
relies on this. You can install that using the following Dockerfile command:
RUN apt-get update
&& apt-get install -y libgdiplus libc6-dev
&& ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
&& ln -s /usr/lib/x86_64-linux-gnu/libdl.so /lib64/libdl.so.2
&& ln -s /usr/lib/x86_64-linux-gnu/libdl.so /lib64/libdl.so
旧答案
现在您可以使用 CoreCompat.System.Drawing nuget包.
For now you can use the CoreCompat.System.Drawing nuget package.
几个月来,我们一直在生产代码中使用它(在视频屏幕截图上绘制),并且效果很好.它基本上是 System.Drawing 的插入式替代品.
We've been using it in production code for a few months (drawing on video screencaps) and it has been working great. It's basically a slot-in replacement for System.Drawing.
这篇关于在类库 (.NET Standard) 中找不到位图类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!