views:

73

answers:

1

I would like to write a program that can mirror a portion of the main display into a new window. Ideally this new window could then be displayed on an external monitor. I have seen this uiltity for a flightsim that does this on a pc (a multifunction display extractor).

CLick here for a screenshot of the program (MFD Extractor)

This would be a live window ie. constantaly updated video display not just a static graphic.

I have looked at screen magnifiers or vnc clients for ideas but I think I need to write something from scratch. I have tried to do some reading on osx programing but where do I start in terms of gaining access to the display? I somehow need to extract the graphics from a particular program. Is it best to go near the final output stage (the individual pixels sent to the display) or somewhere nearer the window management stage.

Any ideas or pointers would be much appreciated. I just need somewhere to start from.

Regards,

A: 

There are a few ways to do this:

  1. Quartz Display Services will let you get access to the video memory for a screen.
  2. Quartz Window Services (a.k.a. CGWindow) will let you create an image of everything that lies below a window. If you create a borderless, transparent, empty, high-level window whose frame occupies an entire screen, everything below it will be everything on that screen. (Of course, you could create a smaller window in order to copy a section of the screen.)
  3. There's also a way to do it using OpenGL that I never fully understood. That technique is demonstrated by a couple of code samples, OpenGLScreenSnapshot and OpenGLCaptureToMovie. It's more or less obsoleted by CGWindow, though.

Each of those will get you an image that you can then show or write to a file or something.

To show an image, use NSImageView or IKImageView. If you want to magnify it, IKImageView has a zoomFactor property, but if you want nearest-neighbor scaling (like Pixie, DigitalColor Meter, or xScope), I think you'll need to write a custom view for that (but even that isn't all that hard).

Peter Hosey
Thanks for your suggestions. Would it be feasable using these methods (such as CGWindowListCreateImageFromArray from Quartz Window Services and NSImageView) to create a live video mirroring display as opposed to static images?I suppose it would depend on the polling or refresh rate, which could be timing or screen-update interrupt rate.Or, if this is my intention are there other routes, or alternative functions I should be using?Thanks aagain.
Adam
Adam: Yes, it is.
Peter Hosey