I try to generate sprites from StreamingAsets folder but I'm stuck when it comes to create texture from formats other than PNG and JPG. Following code:
byte[] bytes = File.ReadAllBytes (filepath); // 256x256 .tga image file
Texture2D texture = new Texture2D (1, 1);
texture.LoadImage (bytes);
generates 8x8 texture which is:
So how do I create textures from other types of images?
TGA format is not supported. You have to write your own wrapper to do so but many of these wrappers do exist already. See the TGALoader
class. It is very simple to use.
Texture2D texture = TGALoader.LoadTGA(sfilepath);
Your TGA image is now loaded into the texture
variable.