iOS实现截图的代码
jopen
11年前
- (UIImage *) captureScreen { UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); [keyWindow.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; }如果要保存到相册:
- (void)saveScreenshotToPhotosAlbum:(UIView *)view { UIImageWriteToSavedPhotosAlbum([self captureScreen], nil, nil, nil); }