文章标题

- (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;
}
阅读更多
个人分类: iOS
上一篇IOS控件学习:UILabel常用属性与用法
下一篇全局滑动返回的第三方库
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭