iOS 截图

- (UIImage *)captureScreenWithSize:(CGRect )rect
{
    UIImage *image = nil;
    // 截图
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [keyWindow.layer renderInContext:context];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([image CGImage], rect)]; // 裁剪部分区域
    
    return image;
}

猜你喜欢

转载自blog.csdn.net/lanliang901125/article/details/27643203