如何在Processing中用鼠标获取RGB颜色数值

要做一个抠图应用,所以随手做了个鼠标取色,代码如下:

1 void mousePressed(){
2   int imgC = get(mouseX,mouseY);
3   int R = (imgC >> 16) & 0xFF;
4   int G = (imgC >> 8) & 0xFF;
5   int B = imgC & 0xFF;
6   println("Current position color: Red = "+R+", Green = "+G+", Blue = "+B);
7 }

放到sketch最后面,运行后在画布中单击鼠标就能获取当前像素的颜色值。

 

posted on 2014-07-27 12:32  o0松鼠0o  阅读(1405)  评论(0编辑  收藏  举报