- Home /
Read Files from a folder -> Load their icons as Textures
Hi,
Basic question: Why does access to some System.Drawing classes work from inside the Editor (via my own DLL file, which in turn calls System.Drawing), but not from a built standalone?
Detailed question: I am trying to create something like a filesystem inside Unity. For this, I load the Icons from files, apply them to Texture2D, and show that on some meshes.
To accomplish this, I need access to Icon and Bitmap classes (in System.Drawing). I do all this in an external DLL file. I KNOW that Unity "does not allow to access System.Drawing", but interestingly, it works perfectly fine from within the Editor. If I try to build this, it crashes on build and tells me that System.Drawing must not be included in the build. So I tried to cheat - I copied the System.Drawing.dll into the Plugins folder, and voila - the standalone gets built. But there are no textures, and the logfile shows a "TypeLoadingError" with the type "Gdip", when the
So the Icon class is working just fine, but the Bitmap class throws an error, but not in the editor.
Has, by chance, anyone got some similar problems (quite unlikely, I know) - and maybe even a solution?
I think the solution would be to [DllImport] the gdiplus.dll methods used by System.Drawing... but no luck so far.
Felix
Boah, all this stuff sounds so strange by reading it again... but maybe someone can help, though :).
How about avoiding System.Drawing altogether and just load a raw jpeg or png and use Texture2D.LoadImage?
That doesn't work for loading icons of files though, you'd have to make a texture for every file on your computer
I need to use System.Drawing to extract the icons associated with the files, like $$anonymous$$ike said.
Ah, ok, I thought your files were icons, now I get it. Do you have to extract the icons dynamically, or could you preprocess them and include the icons as separate assets? (This would work cross-platform as well -- extract icons on the Windows dev box, use them anywhere ... not sure if cross-platform is a concern for you though.)
Answer by zeropoint · Mar 02, 2011 at 09:21 AM
Using TextAsset class would answer your question if you are trying just to load images stored as files. Here i am copying example from the TextAsset.bytes page of documentation:
// Load a .jpg or .png file by adding .bytes extensions to the file // and dragging it on the imageTextAsset
var imageTextAsset : TextAsset;
function Start () { var tex = new Texture2D (4, 4); tex.LoadImage(imageTextAsset.bytes); renderer.material.mainTexture = tex; }
from here.
Hope this suits your requirement...
Your answer
![](https://koobas.hobune.stream/wayback/20220613101115im_/https://answers.unity.com/themes/thub/images/avi.jpg)