CGRect imageRect;
imageRect = CGRectMake(imageX, imageY, imageW, imageH);
// 截图
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
UIImage *imge = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef imageRefRect = CGImageCreateWithImageInRect(imge.CGImage, imageRect);
UIimage * cutImage = [[UIImage alloc] initWithCGImage:imageRefRect];
self.imageSavePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"cutImage"];
NSData *imageViewData = UIImagePNGRepresentation(cutImage);
[imageViewData writeToFile:self.imageSavePath atomically:YES]; // 保存截图到沙盒目录
ios 部分截屏/将手机页面某一部分转换为图片/截图
最新推荐文章于 2023-04-03 20:29:01 发布