C# 我怎么能;将从.dll中的Properties.Resources读取的图像数据转换为图像、纹理2D或sprite?

C# 我怎么能;将从.dll中的Properties.Resources读取的图像数据转换为图像、纹理2D或sprite?,c#,dll,bitmap,unity3d,resourcemanager,C#,Dll,Bitmap,Unity3d,Resourcemanager,首先,由于某种原因,我无法使用我的c#脚本中的System.Drawing。我在Unity3d中工作,每次加载脚本时,库引用都会被踢出 我正在使用此方法访问dll的资源 //DaiM.Reality is the namespace // fgla is a class Assembly asm = typeof(DaiM.Reality.fgla).Assembly; string resourcename = asm.GetName().Name

首先,由于某种原因,我无法使用我的c#脚本中的System.Drawing。我在Unity3d中工作,每次加载脚本时,库引用都会被踢出

我正在使用此方法访问dll的资源

//DaiM.Reality is the namespace 
// fgla is a class

            Assembly asm = typeof(DaiM.Reality.fgla).Assembly;
        string resourcename = asm.GetName().Name + ".Properties.Resources";
        ResourceManager rm = new ResourceManager(resourcename, asm);
        Texture2D imh = (Texture2D)rm.GetObject("flag"); // the problem
// error :: InvalidCastException: Cannot cast from source type to destination type.
如果我可以使用System.Drawing,那么我可以从位图中读取像素并将其应用到新的纹理2D。但unity不允许我使用系统。绘图。我猜这是因为System.Drawing library和UnityEngine library中的某些类与系统冲突。Unity的默认库中不包括绘图。您应该自己将System.Drawing.dll导入到项目中。有关更多信息:

2) 您尝试导入的DLL应在编译时将目标框架选项设置为Unity能够理解的某个版本(当前为2.0)。确保设置正确

3) 请看这篇从DLL导入图像的文章:


希望这有帮助。

我看到了系统。绘图库是2.0版的。好的,我会的。非常感谢这很有帮助只是一件事。我看到了'Stream myStream=myAssembly.GetManifestResourceStream(“hutongames.PlayMakerEditor.Editor.Resources.”+resourceName+“.png”);`他说可以,但我不知道他指向的是属性,然后是资源,这个脚本是从dll内部运行的?好的,它直接指向资源文件夹。它一直说我的流是空的。这可能是dll方面的问题吗?对不起。我错过了一场比赛