2
我正在开发一个类似mac的应用程序的放大镜。我的目标是能在放大时查明单个像素我正在使用的mouseMoved此代码(与事件:NSEvent):CGWindowListCreateImage在放大时会产生模糊的cgImage
let captureSize = self.frame.size.width/9 //9 is the scale factor
let screenFrame = (NSScreen.main()?.frame)!
let x = floor(point.x) - floor(captureSize/2)
let y = screenFrame.size.height - floor(point.y) - floor(captureSize/2)
let windowID = CGWindowID(self.windowNumber)
cgImageExample = CGWindowListCreateImage(CGRect(x: x, y: y, width: captureSize,
height: captureSize), CGWindowListOption.optionOnScreenBelowWindow, windowID,
CGWindowImageOption.bestResolution)
的cgImage的创作发生在CGWindowListCreateImage方法。当我后来画此在的NSView,结果是这样的:
它看起来模糊不清/像创建cgImage的过程中,施加一定的反走样。我的目标是获得每个像素的锐利表示。任何人都可以将我指向正确的方向吗?
亲爱@Tuslareb,你能否如此善良,并提供一个“背景”的例子?我面临同样的问题。我也使用'CGWindowListCreateImage'生成截图,但缩放时产生的CGImage会模糊。我基本上将屏幕截图转换为“NSImage”,然后将其显示在ImageView中。 – ixany
@ixany我用一些示例代码更新了我的答案。基本上,我在CGWindowListCreateImage调用中绘制了自定义NSView的drawRect方法中的CGImage。你在CGWindowListCreateImage调用中使用了哪个CGWindowImageOption? – Tuslareb