简体   繁体   English

在 Unity3D 中的 System.Drawing 中找不到位图

[英]Bitmap not found in System.Drawing in Unity3D

Maybe just an oversight on my part, but I can't make sense of this:也许只是我的疏忽,但我无法理解这一点:

However, if I try use a bitmap, I get the following error:但是,如果我尝试使用位图,则会出现以下错误:

Error CS0246 The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)错误 CS0246 找不到类型或命名空间名称“位图”(您是否缺少 using 指令或程序集引用?)

VS19-IntelliSense suggests to install the package System.Drawing.Common , however if I do that, I get yet another error, stating: VS19-IntelliSense 建议安装System.Drawing.Common包,但是如果我这样做,我会收到另一个错误,说明:

The type name 'Bitmap' could not be found in the namespace 'System.Drawing'.在命名空间“System.Drawing”中找不到类型名称“Bitmap”。 This type has been forwarded to assembly 'System.Drawing.此类型已转发到程序集“System.Drawing”。

How can I resolve this issue to actually use the Bitmap class?如何解决此问题以实际使用Bitmap类?

Copy the System.Drawing.dll from C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0 into your Unity project folder.System.Drawing.dllC:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0复制到您的 Unity 项目文件夹中。 I put mine under Assets/Plugins/System.Drawing.dll .我把我的放在Assets/Plugins/System.Drawing.dll

This version will contain the Bitmap class.此版本将包含Bitmap类。 You will still have an error in the editor, but everything will compile fine and you should be able to use Bitmap in Visual Studio.您在编辑器中仍然会出现错误,但一切都会正常编译,您应该能够在 Visual Studio 中使用 Bitmap。


A problem you may now encounter when using certain types from this dll (eg Color , RectangleF ) is that Unity gets confused between the 4.0 and 2.0 versions of the dll files.在使用此 dll 中的某些类型(例如ColorRectangleF )时,您现在可能会遇到的一个问题是 Unity 在 4.0 和 2.0 版本的 dll 文件之间混淆。 The only solution I found to resolve this is to change Api compatibility Level from .NET Standard 2.0 to 4.0 under Edit > Project Settings... > Player .我发现解决此问题的唯一解决方案是在Edit > Project Settings... > Player下将Api compatibility Level.NET Standard 2.0更改为4.0 . .

If you choose not to do this, you will find that there is System.Drawing in the C:/Program Files/Unity/Hub/Editor/2020.2.0f1/Editor/Data/NetStandard/ref/2.0.0/netstandard.dll .如果您选择不这样做,你会发现,有System.DrawingC:/Program Files/Unity/Hub/Editor/2020.2.0f1/Editor/Data/NetStandard/ref/2.0.0/netstandard.dll . Removing this dll will cause Unity to complain until you restore it.删除此 dll 将导致 Unity 抱怨,直到您恢复它。

There are solutions suggesting to modify C:\\Program Files\\Unity\\Hub\\Editor\\2020.2.0f1\\Editor\\Data\\NetStandard\\compat\\2.0.0\\shims\\netfx\\System.Drawing.dll or C:\\Program Files\\Unity\\Hub\\Editor\\2020.2.0f1\\Editor\\Data\\MonoBleedingEdge\\lib\\mono\\4.5\\System.Drawing.dll , but I would advice against this as it would impact other projects using the same Unity version.有解决方案建议修改C:\\Program Files\\Unity\\Hub\\Editor\\2020.2.0f1\\Editor\\Data\\NetStandard\\compat\\2.0.0\\shims\\netfx\\System.Drawing.dllC:\\Program Files\\Unity\\Hub\\Editor\\2020.2.0f1\\Editor\\Data\\MonoBleedingEdge\\lib\\mono\\4.5\\System.Drawing.dll ,但我建议不C:\\Program Files\\Unity\\Hub\\Editor\\2020.2.0f1\\Editor\\Data\\MonoBleedingEdge\\lib\\mono\\4.5\\System.Drawing.dll ,因为它会影响使用相同 Unity 版本的其他项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM