开发者

Is there an alternative to the CALayer -renderInContext: method?

开发者 https://www.devze.com 2022-12-27 03:39 出处:网络
I need a way of capturing a view or the screen with everything开发者_高级运维 just exactly like it appears on screen. -renderInContext: won\'t do that. Are there any alternatives to this?Several, but

I need a way of capturing a view or the screen with everything开发者_高级运维 just exactly like it appears on screen. -renderInContext: won't do that. Are there any alternatives to this?


Several, but start with:

UIGetScreenImage();

Which returns a CGImageRef. If you use this, note that the image is retained, and you should release it.

Edit:

Add for completeness the main other way to do this:

UIWindow *aWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
UIGraphicsBeginImageContext(aWindow.frame.size);
[[aWindow layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
0

精彩评论

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