我正在开发一个需要比较两个图像的应用程序,以便查看它们之间的差异,并且应用程序会针对不同的图像重复执行此操作.所以我目前这样做的方法是将图像作为两个NSBitmapImageRep,然后使用colorAtX: y:函数来获取NSColor对象,然后检查RGB组件.但这种方法非常缓慢.因此,围绕互联网进行研究,我发现帖子说更好的方法是使用函数bitmapData获取位图数据,该函数返回unsigned char.对我来说不幸的是我不知道如何从这里进一步发展,我发现的帖子都没有告诉你如何从中获得每个像素的RGB分量bitmapData.所以目前我有:
NSBitmapImageRep* imageRep = [self screenShot]; //Takes a screenshot of the content displayed in the nswindow
unsigned char *data = [imageRep bitmapData]; //Get the bitmap data
//What do I do here in order to get the RGB components?
Run Code Online (Sandbox Code Playgroud)
谢谢