Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Texture2D.LoadImage texture format override problem

Discussion in 'Editor & General Support' started by ArtyBrest, Apr 25, 2016.

  1. ArtyBrest

    ArtyBrest

    Joined:
    Feb 20, 2014
    Posts:
    10
    Hi.
    I use LoadImage() to work with external textures (JPG and PNG files) in my project. It has a problem with texture format preserving. For example I have 8-bit JPG (or PNG) texture (gray) and I want to upload it to Alpha8 format texture using next piece of code:
    Code (CSharp):
    1. Texture2D outTexture = new Texture2D( 1, 1, TextureFormat.Alpha8, false, true );
    2. if ( outTexture.LoadImage( atlasRawBytes.bytes, true ) )
    3. {
    4.     // use texture..
    5. }
    But texture format is overrided to RGB24 after loading. I can use LoadRawTextureData() to upload manually decoded jpg, but c# jpg decoding is too slow.
    Could LoadImage() have a flag to preserve specified texture format or to respect file texture format?
    Thanks.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,555
    You can see this behaviour is documented in the Texture2D.LoadImage docs (here: http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html):
     
  3. zwcloud

    zwcloud

    Joined:
    Mar 15, 2016
    Posts:
    377