Search Unity

[SOLVED]GetPixel, Returns Incorrect Color

Discussion in 'Editor & General Support' started by renman3000, Oct 31, 2018.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Hi there,
    I am using GetPixel() return color, to level build. My issue is that, despite double checking and rechecking that my image texture source colours are only (white, black, red, and green), I am getting number of other colours, throwing out my pattern.

    What could be the issue?


    SOLUTUION:
    To insure the colours are at full value....
    Code (csharp):
    1.  
    2.  
    3.  
    4.                     Color32 color = texture2D.GetPixel(x, y);
    5.  
    6.                     //insure no deviance in color.
    7.                     byte r = color.r;
    8.                     byte g = color.g;
    9.                     byte b = color.b;
    10.                     byte a = 255;
    11.                     byte half = 255 / 2;
    12.  
    13.  
    14.                     if(r > half){
    15.                         r = 255;
    16.                     }else{
    17.                         r = 0;
    18.                     }
    19.                     if (b > half)
    20.                     {
    21.                         b = 255;
    22.                     }else
    23.                     {
    24.                         b = 0;
    25.                     }
    26.                     if (g > half)
    27.                     {
    28.                         g = 255;
    29.                     }else
    30.                     {
    31.                         g = 0;
    32.                     }
    33.                     color = new Color32(r, g, b, a);
    34.  
    35.  
     
    Last edited: Oct 31, 2018