文章标题

原创 2015年11月18日 17:10:42
- (UIImage *)rn_screenshot {
    UIGraphicsBeginImageContext(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT));
    if([self.view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]){
        [self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
    }
    else{
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    }
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGImageRef imageRef = image.CGImage;
    CGRect rect =CGRectMake(0, SCREEN_HEIGHT - 357, SCREEN_WIDTH, 357);//这里可以设置想要截图的区域
    CGImageRef imageRefRect =CGImageCreateWithImageInRect(imageRef, rect);
    UIImage *sendImage = [[UIImage alloc] initWithCGImage:imageRefRect];
    NSData *imageData = UIImageJPEGRepresentation(sendImage, 0.75);
    image = [UIImage imageWithData:imageData];

    return image;
}
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:文章标题
举报原因:
原因补充:

(最多只允许输入30个字)