Created
August 1, 2014 23:29
-
-
Save DomDomHaas/ea3c2b8f5cdb0c66ee91 to your computer and use it in GitHub Desktop.
get the average RGB form a texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Color getAverageRGB (Texture2D tex) | |
{ | |
Color[] allPixels = tex.GetPixels (0, 0, tex.width, tex.height); | |
float r = 0; | |
float g = 0; | |
float b = 0; | |
int interationSteps = 1; | |
for (int i = 0; i < allPixels.Length; i += interationSteps) { | |
Color pixColor = allPixels [i]; | |
r += pixColor.r; | |
g += pixColor.g; | |
b += pixColor.b; | |
// for (int j = 0; j < tex.height; j += interationSteps) { | |
// } | |
} | |
//Calculate average | |
r /= allPixels.Length; | |
g /= allPixels.Length; | |
b /= allPixels.Length; | |
return new Color (r, g, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment