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.

Question Error“LoadRawTextureData: not enough data provided” even the image info from LoadImage()

Discussion in 'General Graphics' started by Mavericks_Game, Aug 5, 2023.

  1. Mavericks_Game

    Mavericks_Game

    Joined:
    Nov 27, 2019
    Posts:
    5
    I designed an experiment to explore the usage of LoadRawTextureData.

    I knew that before using LoadRawTextureData, I needed to know the dimensions and compression format of the RawTextureData.

    So, I simply used LoadImage to obtain this information. However, even with this approach, I still encountered an error“LoadRawTextureData: not enough data provided”.

    Can someone tell me what went wrong exactly and how to do it correctly?

    Below is my code:

    Code (CSharp):
    1.  
    2.  
    3. Texture2D texture = new Texture2D(2, 2, TextureFormat.ARGB32, false);
    4. texture.LoadImage(rawByteArray);
    5. Texture2D rawTexture = null;
    6. try
    7. {
    8.  
    9.     rawTexture = new Texture2D(texture.width, texture.height, texture.format, false);
    10.     rawTexture.LoadRawTextureData(rawByteArray);
    11.     rawTexture.Apply();
    12. }
    13. catch (Exception e)
    14. {
    15.     Debug.Log(e.ToString());
    16.     throw;
    17. }
    18.