在Objective-C(OS X)中,是“全局显示” Quartz显示服务使用的坐标空间与Cocoa的“屏幕”相同。坐标空间? [英] In Objective-C (OS X), is the "global display" coordinate space used by Quartz Display Services the same as Cocoa's "screen" coordinate space?

查看:136
本文介绍了在Objective-C(OS X)中,是“全局显示” Quartz显示服务使用的坐标空间与Cocoa的“屏幕”相同。坐标空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的应用程序创建一个图像放大镜,可以用来检查不同放大倍率的图像,我遇到了一个路障。我使用Quartz创建一个 CGImageRef 快照的显示我的应用程序的窗口的显示选定部分。问题是,所有不同的OS X技术使用的命名法我真的很困惑。



我使用的功能是 CGDisplayCreateImageForRect CGDirectDisplayID display,CGRect rect)。该文档说明 CGRect rect 参数是在显示空间中指定的矩形,用于显示被复制到图像中的部分。问题是,我在我的控制台得到的输出不是我的期望。我已经尝试了这么多不同的转换,转换,协调翻转等,我现在100%困惑。



所以,我想我的问题归结为这是:屏幕空间==设备空间==显示空间,以及如何正确转换他或她的视图的框架(这恰好是一个自定义无边框窗口)坐标(左下原点)匹配显示的坐标(top-



如果有人可以让我直线,或指向正确的方向,我会永远感谢。感谢!

解决方案

Quartz使用坐标空间,其中原点(0,0)在主显示屏的左上角。



Cocoa使用坐标空间,其中原点(0,0)是主显示屏的左下角,而y增加。 p>

您可以将窗口的框架从Cocoa转换为Quartz,如下所示:

  NSRect frame = window.frame; 
frame.origin.y = NSMaxY(NSScreen.screens [0] .frame) - NSMaxY(frame);
CGRect quartzRect = NSRectToCGRect(frame);

注意:您不使用窗口的 -screen ,你总是使用主屏幕。



这是一个矩形窗口坐标。对于视图中的rect,首先使用 - [NSView convertRect:toView:] 将视图坐标转换为窗口坐标,其中 nil 作为表示窗口的目标视图。这将为 someView.bounds 而不是 someView.frame 做正确的事,因为视图的框架在superview的坐标系。


I'm attempting to create an image "loupe" for my application that can be used to inspect images at different magnification levels, and I have run into a bit of a road bump. I'm using Quartz to create a CGImageRef snapshot of a selected portion of the display my app's window is on. The problem is, the nomenclature used by all of the different OS X technologies has me really confused.

The function I'm using is CGDisplayCreateImageForRect(CGDirectDisplayID display, CGRect rect). The documentation states the CGRect rect parameter is the "rectangle, specified in display space, for the portion of the display being copied into the image." The problem is, the output I'm getting in my console isn't what I was expecting. I've tried so many different conversions, transformations, coord flips, etc., that I'm 100% confused now.

So, I guess my question boils down to this: Does screen space == device space == display space, and how does one properly convert his or her view's frame (which happens to be a custom borderless window) coordinates (bottom-left origin) to match the display's coordinates (top-left origin)?

If someone could set me straight, or point me in the right direction, I'd be forever appreciative. Thanks!

解决方案

Quartz uses a coordinate space where the origin (0, 0) is at the top-left of the primary display. Increasing y goes down.

Cocoa uses a coordinate space where the origin (0, 0) is the bottom-left of the primary display and increasing y goes up.

You can convert a window's frame from Cocoa to Quartz like so:

NSRect frame = window.frame;
frame.origin.y = NSMaxY(NSScreen.screens[0].frame) - NSMaxY(frame);
CGRect quartzRect = NSRectToCGRect(frame);

Note: you don't use the window's -screen, you always use the primary screen.

This is for a rect in window coordinates. For a rect in a view, first convert from view coordinates to window coordinates using -[NSView convertRect:toView:] with nil as the destination view signifying the window. This would do the right thing for someView.bounds but not for someView.frame, since a view's frame is in the superview's coordinate system.

这篇关于在Objective-C(OS X)中,是“全局显示” Quartz显示服务使用的坐标空间与Cocoa的“屏幕”相同。坐标空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆