Determine if image is Grayscale or Color using JavaScript?

假如想象 提交于 2020-01-12 07:46:42

问题


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


回答1:


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

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




回答2:


  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.



来源:https://stackoverflow.com/questions/8329765/determine-if-image-is-grayscale-or-color-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!