- Home /
How to load with Texture2D.LoadImage?
Link: http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.LoadImage.html
I want to use this function to load a PNG file from file given path but I don't know how to create a Texture2D
object beforehand. What size do I specify? Do I need to explicitly specify a size? If so, how do I find out the image's size?
Answer by ArkaneX · Sep 03, 2013 at 02:23 PM
You don't have to specify the size, because texture data is replaced.
EDIT: just noticed, that you want to load from path. Texture2D.LoadImage requires image byte array. If you have path only, then I suggest reading with Resources.Load or WWW class (if your asset is outside of Resources folder).
The example above uses new Texture2D (4, 4)
and it seems to be working but I would really like to know more on the matter.
There is nothing special in that size. I guess it was just arbitrarily chosen by documentation author. Please read the description below example - it states that texture size and format might change after LoadImage.
If you initially create Texture2D of size 4x4, but your image is bigger, then resulting texture will have width and height equal to your image width and height.
Hello,
I wonder what your code to display an image in a texture ?
Thanks in advance.