如何在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最后面,运行后在画布中单击鼠标就能获取当前像素的颜色值。

爱好编程、喜欢计算机、也喜欢美食~
原文地址:https://www.cnblogs.com/x5115x/p/3871235.html