获取屏幕图像的两种方法
一、
typedef struct __IOSurface *IOSurfaceRef;
UIKIT_EXTERN CGImageRef UICreateCGImageFromIOSurface(IOSurfaceRef);
- (void)takeScreenshotAndSaveToPhotosAlbum {
IOSurfaceRef ioSurfaceRef = (__bridge IOSurfaceRef)([UIWindow performSelector:@selector(createScreenIOSurface)]);
CGImageRef cgImageRef = UICreateCGImageFromIOSurface(ioSurfaceRef);
UIImage *uiImage = [UIImage imageWithCGImage:cgImageRef];
CFRelease(ioSurfaceRef);
CGImageRelease(cgImageRef);
UIImageWriteToSavedPhotosAlbum(uiImage, nil, nil, nil);
}
二、
- (void)takeScreenshotAndSaveToPhotosAlbum {
extern UIImage *_UICreateScreenUIImage();
UIImage *screenshot = _UICreateScreenUIImage();
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
}