- Home /
Creating bitmap texture2d during runtime
Hey All,
I have a need that my image will be downloaded to the application during runtime outside of the Application.dataPath (Assets folder) in bmp format. Using which I need to create my texture2D during run time. I am able to do this if the image is a png or jpg but not for a bitmap image. I am restricted to the fact that this image is going to be of bitmap format.
For JPG or Png I am able to create runtime texture2D using the following code
CreateRunTimeTexture(string fileName)
{
byte[] pngBytes = System.IO.File.ReadAllBytes(fileName);
Texture2D pngTexture = new Texture2D(74, 74, TextureFormat.RGB24, false);
pngTexture.LoadImage(pngBytes);
}
Since UnityEditor is able to handle bitmap images I believe what am trying to do is possible. Any help is much appreciated.
Code example pointed above is to show how am doing for png/jpg. If bitmap needs to be done through someother fashion thats is fine. Currently am not able to process the bitmap bytes properly to achieve the result I am looking for.
One hack suggested to me was to use a program during runtime to convert bmp to png and then load them in to texture and then delete the png. I am able to do this but if bmp could be directly loaded it would be great.
Sorry for not being clear. Code example is to show how am currently doing. Even if not with LoadImage if there is another way to accomplish what am trying to do would be great. Google search as well as searching in unity forums for this is not fruitful till now. Think am missing something. Unity Editor is able to handle bitmap so assu$$anonymous$$g they are formating the bitmap bytes in some fashion while reading to get this right. Either unity people or people who have done this before might be able to point some fundamental thing which am missing while doing this.
Your answer
Follow this Question
Related Questions
Modifying an heightmap at runtime 2 Answers
Gradual Terrain Smoothing from a Flat Area (at Runtime) 0 Answers
what is the best way to implement minigames into my own full blown unity game. 0 Answers
How to create road or buildings during running the game 2 Answers
How to refresh rigidbody colliders modified at runtime 0 Answers