How can I get the average colour of an image

后端 未结 6 509
温柔的废话
温柔的废话 2020-12-07 16:57

I want to be able to take an image and find out what is the average colour. meaning if the image is half black half white, I would get something in between... some shade of

6条回答
  •  囚心锁ツ
    2020-12-07 17:23

    Use the Bitmap.getPixels() method to get the color values. Then to calculate the average you have to decide what you mean by that. In a grayscale image it is simple, but with colors there are no such thing as an average. You can separate into components (for example RGBA), and take the average of each component. An alternative is to search for the most commonly used color, and there are several other options I'm sure. Play with it :)

提交回复
热议问题