Thanks to visit codestin.com
Credit goes to github.com

Skip to content

截屏模糊变清晰处理 #2

@luoei

Description

@luoei

方法一:

- (UIImage *)takeSnapshotWithFrame:(CGRect)frame
{
    
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0);
    [img drawInRect:CGRectMake(0, -frame.origin.y, img.size.width, img.size.height)];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return  image;
}

方法二:

- (UIImage *)takeSnapshotWithFrame:(CGRect)frame
{
    
    UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
    
    [self drawViewHierarchyInRect:CGRectMake(0, -frame.origin.y, self.bounds.size.width, self.bounds.size.height) afterScreenUpdates:YES];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();

    return  image;
}

方法二是贴出来讨论的,在效果上面欠缺。 @bref-Chan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions