- Home /
Can't get LoadImage working
I need to open a image and transform to byte to run by LoadImage here is my code:
Texture2D defaultMapTexture = new Texture2D(512, 512, TextureFormat.ARGB32, false);
string completedPath = "file://C:/a.bmp";
byte [] textureData = File.ReadAllBytes(completedPath);
defaultMapTexture.LoadImage(textureData);
defaultMapTexture.Apply();
Rect rect = new Rect(20f, 20f, 1106, 906);
GUI.DrawTexture(rect, defaultMapTexture);
Have you tried using a PNG file since I do not think that B$$anonymous$$P files are supported by this function?
Answer by nRadiant · Jan 22, 2014 at 03:05 PM
numberkruncher is right... Documentation says:
This function loads a JPG or PNG image from raw byte[] array
Here is the documentation that says that you need JPG or PNG
Convert to jpg or png and you will be good to go.
I have converted to PNG and JPG, nothing works, it only show me a alpha white, like with B$$anonymous$$P image :(
Answer by poncho · Jan 22, 2014 at 05:13 PM
not sure if file's location is relevant, but you could add it to your assets folder and use Resources.Load, if it does not gives you the texture, try with the file a.PNG moving it to assets/Resources
Texture2D myTexture = Resources.Load("a.PNG") as Texture2D;
then draw it where you want it.
GUI.DrawTexture(rect, myTexture);
I'm a beginner, can you tell me where is Assets folder?
Assets folder is where everything you send to project window(not hierarchy) lives, right click on anything in your project window, go to source folder, or any one with similar message, root folder, origin, explore, not sure
Your answer