截取指定区域

//frame 是你所需要的区域大小

+(UIImage *)screenshotsImageFram:(CGRect)frame{

    UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];

    UIGraphicsBeginImageContext(screenWindow.frame.size);//全屏截图,包括window

    [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    CGRect rect1 =frame;

    UIImage * image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([viewImage CGImage], rect1)];

    return image;

}

posted @ 2017-09-25 14:48  LiziBlog  阅读(265)  评论(0编辑  收藏  举报