开发者

UIGetScreenImage - Private API

开发者 https://www.devze.com 2022-12-13 18:23 出处:网络
I was using UIGetScreenImage in my app, however, as everyone knows Apple is rejecting apps using private APIs. I have researched alternate ways to do this with takepicture but you get different size i

I was using UIGetScreenImage in my app, however, as everyone knows Apple is rejecting apps using private APIs. I have researched alternate ways to do this with takepicture but you get different size images as well as the annoying snapshot so开发者_如何学运维und. Microsoft tag. Quickmark and Redalaser all use the UIGetScreenImage (it's obvious) but I want to do this legally. Does anyone out there have any suggestions. Much appreciated.


This might work... I think that it was the answer to another SO question.

-(UIImage *)captureView:(UIView *)view {
    CGRect screenRect = [[UIScreen mainScreen] bounds];    
    UIGraphicsBeginImageContext(screenRect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    [[UIColor blackColor] set]; 
    CGContextFillRect(ctx, screenRect);
    [view.layer renderInContext:ctx];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage; 
}


UIGetScreenImage is currently Apple's recommended way of capturing the screen. It's sort of a private method, but they've stated in the developer forums that using it is acceptable until they add a public-API equivalent.

Update: UIGetScreenImage is no longer allowed, as of iOS 4; I believe the approved way to take pictures is now using the AVFoundation framework.


The best (and the slowest) thing to do is to file a feature request at Apple.

0

精彩评论

暂无评论...
验证码 换一张
取 消