如何拍摄UIWebView
控件的快照/屏幕截图?
接受的答案是正确的,但屏幕截图不是视网膜分辨率.使用UIGraphicsBeginImageContextWithOptions
和设置其缩放参数0.0f使其以原始分辨率捕获.
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [keyWindow.layer renderInContext:context]; UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();