I'm trying to take a screenshot of a view.
I'm using the code at the following link, which is working fine with one exception:
cocoa: how to render view to image?
The problem I have is that if I drag the application window to my second monitor the screen capture grabs the wrong rect. Essentially the rect has been displaced vertically, or is possibly using an origin in the top left rather than bottom left.
The odd thing is that the app works fine on the launch monitor, but when I drag it to the second monitor (without closing and restarting the app) the rect capture goes wrong. If I drag the app back to the launch monitor everything starts working again.
The primary monitor and secondary monitor have different resolutions.
The code that converts the rect is as follows:
NSRect originRect = [aView convertRect:[aView bounds] toView:[[aView window] contentView]];
NSRect rect = originRect;
rect.origin.y = 0;
rect.origin.x += [aView window].frame.origin.x;
rect.origin.y += [[aView window] screen].frame.size.height - [aView window].frame.origin.y - [aView window].frame.size.height;
rect.origin.y += [aView window].frame.size.height - originRect.origin.y - originRect.size.height;
Does anyone know why this is calculating correctly on the launch monitor, but miscalculating on secondary monitors?
The problem must be related to the different resolutions, but I can't see why the call to convertRect:toView (or subsequent calculations) isn't working.
BTW, I'm developing this on 10.8.4 and targeting 10.7.
Thanks
Darren.