Macos 检测单个像素颜色变化的程序?

Macos 检测单个像素颜色变化的程序?,macos,colors,pixel,Macos,Colors,Pixel,我想要一个程序,我可以在屏幕上输入一个特定像素的坐标,当这个像素的颜色改变时,就会发生一些事情。特别是要播放的音乐 我有一台macbook电脑,对编程很陌生,有什么建议吗?我不知道如何将屏幕的当前图像作为像素数据获取,但当您这样做时,它很可能是作为原始数组的无符号字符。该数组可以是多种不同格式中的任意一种,但最常见的是4字节RGBA,这意味着每个组件获得1字节的信息。像素数据通常像书中的文本一样排列:从左到右,从上到下 假设你的像素在x,y的位置。为了获得像素数据的索引,您需要执行以下操作: i

我想要一个程序,我可以在屏幕上输入一个特定像素的坐标,当这个像素的颜色改变时,就会发生一些事情。特别是要播放的音乐


我有一台macbook电脑,对编程很陌生,有什么建议吗?

我不知道如何将屏幕的当前图像作为像素数据获取,但当您这样做时,它很可能是作为原始数组的无符号字符。该数组可以是多种不同格式中的任意一种,但最常见的是4字节RGBA,这意味着每个组件获得1字节的信息。像素数据通常像书中的文本一样排列:从左到右,从上到下

假设你的像素在x,y的位置。为了获得像素数据的索引,您需要执行以下操作:

int width;       //set to the width of the image
int height;      //set to the height of the image
int index;

//number of bytes per pixel * number of pixels per row * number of rows
index = 4 * width * y;     //get the index of the start of the correct row

//number of bytes per pixel * number of pixels to go across
index += 4 * x;            //get the index of the correct column in the row

// pixels[index] = red byte
// pixels[index + 1] = green byte
// pixels[index + 2] = blue byte
// pixels[index + 3] = alpha byte
// pixels[index - (any number)] = previous pixels
// pixels[index + (any number more than 3)] = future pixels
现在您已经知道如何访问特定像素的像素数据,只需在程序开始时存储给定像素的RGBA值,并且在程序运行时,偶尔使用计时器将当前颜色与存储的颜色进行比较。当他们不一样的时候,做点什么,播放音乐


希望这有帮助

我不知道如何将屏幕的当前图像作为像素数据获取,但当您这样做时,它很可能将作为基本数组unsigned char获取。该数组可以是多种不同格式中的任意一种,但最常见的是4字节RGBA,这意味着每个组件获得1字节的信息。像素数据通常像书中的文本一样排列:从左到右,从上到下

假设你的像素在x,y的位置。为了获得像素数据的索引,您需要执行以下操作:

int width;       //set to the width of the image
int height;      //set to the height of the image
int index;

//number of bytes per pixel * number of pixels per row * number of rows
index = 4 * width * y;     //get the index of the start of the correct row

//number of bytes per pixel * number of pixels to go across
index += 4 * x;            //get the index of the correct column in the row

// pixels[index] = red byte
// pixels[index + 1] = green byte
// pixels[index + 2] = blue byte
// pixels[index + 3] = alpha byte
// pixels[index - (any number)] = previous pixels
// pixels[index + (any number more than 3)] = future pixels
现在您已经知道如何访问特定像素的像素数据,只需在程序开始时存储给定像素的RGBA值,并且在程序运行时,偶尔使用计时器将当前颜色与存储的颜色进行比较。当他们不一样的时候,做点什么,播放音乐

希望这有帮助