Determine if image is Grayscale or Color using Jav

2020-06-17 04:13发布

Is it possible to determine if a given image is grayscale or color using JavaScript?

2条回答
Bombasti
2楼-- · 2020-06-17 04:48
  1. draw image to canvas

  2. loop through image data

  3. test for each pixel if red-cahnnel == green-channel == blue-channel (all color-channels have the same value)

if true for all pixels it is grayscale, if you hit the first pixel that does not meat the condition you can stop and it is color.

查看更多
Deceive 欺骗
3楼-- · 2020-06-17 04:59

Take a look at http://www.pixastic.com/lib/docs/actions/colorhistogram/

This will easily provide the data you need to determine this.

查看更多
登录 后发表回答