| Issue 2: | The private API UIGetScreenImage | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Your code is great. But you should replace UIGetScreenImage with "screenshot". Apple Said: "In late 2009, Apple announced it would begin to allow iOS apps to use the private UIGetScreenImage() function. As noted in the announcement, 'A future release of iPhone OS may provide a public API equivalent of this functionality. At such time, all applications using UIGetScreenImage() will be required to adopt the public API.' For applications using UIGetScreenImage() to capture the contents of interface views and layers, the -renderInContext: method of CALayer in the QuartzCore framework should be used instead. For more information, see Technical Q&A 1703, "Screen capture in UIKit applications": <http://developer.apple.com/iphone/library/qa/qa2010/qa1703.html>"
Sep 10, 2010
This doesn't seem to work for me... Does it for anyone else...?
Sep 10, 2010
- (void) updateMirroredScreenOnDisplayLink
{
// from http://developer.apple.com/iphone/library/qa/qa2010/qa1703.html
// bonus, this works in the simulator; sadly, it doesn't capture the status bar
//
// if you are making an OpenGL app, use UIGetScreenImage() above or switch the
// following code to match Apple's sample at http://developer.apple.com/iphone/library/qa/qa2010/qa1704.html
// note that you'll need to pass in a reference to your eaglview to get that to work.
UIGraphicsBeginImageContext([[UIApplication sharedApplication] keyWindow].bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
// get every window's contents (i.e. so you can see alerts, ads, etc.)
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, [window center].x, [window center].y);
CGContextConcatCTM(context, [window transform]);
CGContextTranslateCTM(context, -[window bounds].size.width * window.layer.anchorPoint.x, -[window bounds].size.height * window.layer.anchorPoint.y);
[[window layer] renderInContext:context];
CGContextRestoreGState(context);
}
}
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef mainWindowScreenshot = [image CGImage];
UIGraphicsEndImageContext();
if (mainWindowScreenshot) {
// Copy to secondary screen
mirroredScreenWindow.layer.contents = (id) mainWindowScreenshot;
}
}
Nov 25, 2010
This isn't working for me - I'm just getting a blank screen on my TV Out. Any suggestions?
Dec 16, 2010
It's working for me, except a small video replay gets shown using the UIGetScreenImage method but not using the screenshot method. |
- (void) updateMirroredScreenOnDisplayLink { // Get a screenshot of the main window //CGImageRef mainWindowScreenshot = UIGetScreenImage(); UIWindow *theScreen = [[UIApplication sharedApplication].windows objectAtIndex:0]; UIGraphicsBeginImageContext(theScreen.frame.size); [[theScreen layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *mainWindowScreenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (mainWindowScreenshot) { // Copy to secondary screen mirroredScreenWindow.layer.contents = (id)mainWindowScreenshot.CGImage; // Clean up as UIGetScreenImage does NOT respect retain / release semantics //CFRelease(mainWindowScreenshot); } }