How to get the average color of a sprite? (Unity3d)

user3738071

Im finishing up my asset that I'm putting on the asset store. Right now one of the features require the average color of the sprite. Right now I have a public Color to find the average color, where the user can use the color picker or the color wheel or whatever to choose what they think looks like the average color of the sprite. I want to make it so the script automatically calculates the average sprite color, therefore increasing the accuracy by removing human error and increasing the efficiency by not wasting the users time guessing the average sprite color.

ali.turan

Well there is a post about it in Unity forums. Here the link. And the answer is:

Color32 AverageColorFromTexture(Texture2D tex)
{

        Color32[] texColors = tex.GetPixels32();

        int total = texColors.Length;

        float r = 0;
        float g = 0;
        float b = 0;

        for(int i = 0; i < total; i++)
        {

            r += texColors[i].r;

            g += texColors[i].g;

            b += texColors[i].b;

        }

        return new Color32((byte)(r / total) , (byte)(g / total) , (byte)(b / total) , 0);

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get height of 2D gamobject with sprite renderer component in unity3d 4.5?

From Dev

How to convert EmguCV Image to Unity3D Sprite?

From Dev

How to send GUI texture behind a image having sprite renderer component in unity3D 4.5

From Dev

How to get value Unity3D InputField GUI

From Dev

How to get installed apps list with Unity3D?

From Dev

How do I get touch working in Unity3D?

From Dev

In unity3D, how to get the variable from other gameobject?

From Dev

Laravel + Unity3D = how to get the connected user?

From Dev

How to get value Unity3D InputField GUI

From Dev

How to GET and parse data from website? Unity3D

From Dev

Unity3D Sprite ... but single sided?

From Dev

Unity3D: Sprite no appearing

From Dev

Get average color of UIImage in Swift

From Dev

libGDX get pixel color from sprite or texture

From Dev

How to calculate the average color of a UIImage?

From Dev

Color submeshes in unity3d

From Dev

Color submeshes in unity3d

From Dev

How to change the background color with Sprite Kit

From Dev

How to change color of a sprite over time in melonJS

From Dev

How to change the background color with Sprite Kit

From Dev

Unity3d load sprite from Textures folder

From Dev

Unity3d load sprite from Textures folder

From Dev

How to get steamID from Steamworks API in Unity3D in C#?

From Dev

Unity3D canvas. How I can get camera?

From Dev

Unity3d - How to get Animator's Layer -->Sub-State --> State namehash?

From Dev

How to get variables from AndroidJavaObject into a C# class using Unity3D

From Dev

How to get the 'access_token' in Facebook App for Unity3D

From Dev

How to get variables from AndroidJavaObject into a C# class using Unity3D

From Dev

How to get point of the inscribed circle at the point on the square in C# (Unity3d)

Related Related

  1. 1

    How to get height of 2D gamobject with sprite renderer component in unity3d 4.5?

  2. 2

    How to convert EmguCV Image to Unity3D Sprite?

  3. 3

    How to send GUI texture behind a image having sprite renderer component in unity3D 4.5

  4. 4

    How to get value Unity3D InputField GUI

  5. 5

    How to get installed apps list with Unity3D?

  6. 6

    How do I get touch working in Unity3D?

  7. 7

    In unity3D, how to get the variable from other gameobject?

  8. 8

    Laravel + Unity3D = how to get the connected user?

  9. 9

    How to get value Unity3D InputField GUI

  10. 10

    How to GET and parse data from website? Unity3D

  11. 11

    Unity3D Sprite ... but single sided?

  12. 12

    Unity3D: Sprite no appearing

  13. 13

    Get average color of UIImage in Swift

  14. 14

    libGDX get pixel color from sprite or texture

  15. 15

    How to calculate the average color of a UIImage?

  16. 16

    Color submeshes in unity3d

  17. 17

    Color submeshes in unity3d

  18. 18

    How to change the background color with Sprite Kit

  19. 19

    How to change color of a sprite over time in melonJS

  20. 20

    How to change the background color with Sprite Kit

  21. 21

    Unity3d load sprite from Textures folder

  22. 22

    Unity3d load sprite from Textures folder

  23. 23

    How to get steamID from Steamworks API in Unity3D in C#?

  24. 24

    Unity3D canvas. How I can get camera?

  25. 25

    Unity3d - How to get Animator's Layer -->Sub-State --> State namehash?

  26. 26

    How to get variables from AndroidJavaObject into a C# class using Unity3D

  27. 27

    How to get the 'access_token' in Facebook App for Unity3D

  28. 28

    How to get variables from AndroidJavaObject into a C# class using Unity3D

  29. 29

    How to get point of the inscribed circle at the point on the square in C# (Unity3d)

HotTag

Archive