gpt4 book ai didi

objective-c - 数字色度计逻辑 - 它是如何做到的?

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:06 24 4
gpt4 key购买 nike

所以,这基本上是我好奇的:

  • 这个小工具如何获取鼠标下方的区域(和特定像素)?
  • 然后它如何分析所选点的 RGB 值?

有什么想法吗?也欢迎为我指明正确的方向。


提示:我会对原生 Objective-C/Cocoa 方法更感兴趣。

最佳答案

基本上,DigitalColor Meter 获取鼠标坐标,在该区域周围截取 CGImageRef 屏幕截图,然后访问原始像素数据以计算 RGB 值。

您可以使用 nm 命令发现应用程序调用了哪些 API。在这种情况下:

nm/Applications/Utilities/DigitalColor\Meter.app/Contents/MacOS/DigitalColor\Meter

其中揭示了一些有趣的调用:

U _CGDisplayBounds
U _CGGetDisplaysWithPoint
U _CGSCaptureWindowsContentsToRectWithOptions
U _CGSCurrentInputPointerPosition
U _CGSGetOnScreenWindowCount
U _CGSGetOnScreenWindowList

CGS* 例程是私有(private) SPI - 从好的方面来说,有一个名为 CGWindowListCreateImage()

的公共(public) API 等效项

一旦有了 CGImageRef,就可以使用以下方法访问原始像素数据:

CGImageGetDataProvider
CGDataProviderCopyData

关于objective-c - 数字色度计逻辑 - 它是如何做到的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12291880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com