- (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;
}
文章标题
最新推荐文章于 2023-10-19 15:03:50 发布