简体   繁体   中英

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?)

VS19-IntelliSense suggests to install the package System.Drawing.Common , however if I do that, I get yet another error, stating:

The type name 'Bitmap' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.

How can I resolve this issue to actually use the Bitmap class?

Copy the System.Drawing.dll from C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0 into your Unity project folder. I put mine under Assets/Plugins/System.Drawing.dll .

This version will contain the Bitmap class. 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.


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. 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 . .

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 . Removing this dll will cause Unity to complain until you restore it.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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