Search Unity

Texture2D from .bmp image file (Windows)

Discussion in 'Scripting' started by ironwolf, Feb 21, 2013.

  1. ironwolf

    ironwolf

    Joined:
    Oct 26, 2010
    Posts:
    9
    Hi All.

    I need to load external image in BMP format from disk at a runtime, and use it as a texture. It can't be imported into Unity Scene, and it must be BMP format (it is automatically generated by some other application which support only bmp export).

    Unfortunately Unity Texture2D class support only PNG or JPG format and when I try to use BMP I get small red questionmarks instead of textures.

    I can get bytearray from WWW.bytes but still cannot use it as a Texture since its not JPG/PNG bytearray. I thought I could use System.Drawing namespace from .NET and convert BMP bytearray, to PNG bytearray, which could be easily use as a Unity Texture2D, but System.Drawing is also not supported by Unity and I am in a spot.

    So I would be very grateful for any help.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd have to write a script that imports BMP files. Fortunately, from what I remember, BMP is a fairly brain-dead format that generally doesn't use compression, so it shouldn't be too hard.

    --Eric
     
  3. ironwolf

    ironwolf

    Joined:
    Oct 26, 2010
    Posts:
    9
    Thanks for you answer Eric5h5, but I don't really understand what script you think of. I also thought that bmp is uncompressed format so there shouldn't be a problem, but unfortunately it is because Unity can use only PNG or JPG. So this not a matter of import BMP - it is more a matter of converting uncompressed BMP, to compressed JPG or PNG which is pretty complicated to do in Unity script without System.Drawing. The only solution that came to my mind is some C/C++ plugin which will convert BMP to PNG for Unity, but it is still pretty complicated solution to very simple (as it should be) task.