naveen5886 / iphoneos-screen-mirroring

Automatically exported from code.google.com/p/iphoneos-screen-mirroring
1 stars 0 forks source link

The private API UIGetScreenImage #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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>"

Original issue reported on code.google.com by maurois...@gmail.com on 15 Aug 2010 at 10:42

GoogleCodeExporter commented 9 years ago
- (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); 
    }
}

Original comment by erik.mad...@gmail.com on 17 Aug 2010 at 7:58

GoogleCodeExporter commented 9 years ago
This doesn't seem to work for me... Does it for anyone else...?

Original comment by jvanv...@gmail.com on 10 Sep 2010 at 6:28

GoogleCodeExporter commented 9 years ago
- (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;
    }
}

Original comment by dkf2...@gmail.com on 10 Sep 2010 at 9:30

GoogleCodeExporter commented 9 years ago
This isn't working for me - I'm just getting a blank screen on my TV Out.  Any 
suggestions?

Original comment by ash.furrow on 25 Nov 2010 at 3:07

GoogleCodeExporter commented 9 years ago
It's working for me, except a small video replay gets shown using the 
UIGetScreenImage method but not using the screenshot method.

Original comment by christin...@gmail.com on 16 Dec 2010 at 4:15