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.GetPixel() returns 0.804

Discussion in 'Editor & General Support' started by Wonsder, Nov 15, 2020.

  1. Wonsder

    Wonsder

    Joined:
    Jan 24, 2020
    Posts:
    37
    Hello,
    So I am trying to read pixels from a texture 2d :

    Code (CSharp):
    1. Texture2D texture = new Texture2D(inputDimension.x, inputDimension.y);
    2.             Graphics.ConvertTexture(renderTextures, texture);
    3.  
    4.             for(int j = 0; j < texture.width; j++)
    5.             {
    6.                 for(int k = 0; k < texture.height; k++)
    7.                 {
    8.                     Debug.Log(texture.GetPixel(j, k));
    9.                 }
    10.             }
    11.  
    12.  
    13.             //mostly for debuging
    14.             displayTexture = texture;
    15.  
    16.  
    Now, in the inspector, displayTexture is the right texture, with colors and so.
    But, the GetPixel line only return (0.804, 0.804, 0.804)
    Where did i messed up ?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Bunny83 likes this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,528
    Right. If you have a look at the documentation of Graphics.ConvertTexture.

    I haven't really used ConvertTexture (haven't even noticed when it was added) however from the documentation it seems like render textures are not supported.
     
  4. Wonsder

    Wonsder

    Joined:
    Jan 24, 2020
    Posts:
    37
    Then how i can see the texture2D properly in the inspector ? where does it come from ?