如何屏幕截图tableView的所有内容? (所有内容=可见是+非可见区域)
我试过了:
UIGraphicsBeginImageContext(self.tableView.bounds.size);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = image1;
但它不起作用,我的意思是它的截图只有可见区域:(
我解决了它:))
这是代码:)
+ (UIImage *)captureView:(UIScrollView *)view inContentRect:(CGRect)rect{
UIImage* image = nil;
CGPoint savedContentOffset = view.contentOffset;
CGRect savedFrame = view.frame;
UIGraphicsBeginImageContextWithOptions(view.contentSize, 1, 0);
view.contentOffset = CGPointZero;
view.frame = CGRectMake(0, 0, view.contentSize.width, view.contentSize.height);
[view.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
view.contentOffset = savedContentOffset;
view.frame = savedFrame;
UIGraphicsEndImageContext();
// after all of this, crop image to needed size
return [Utils cropImage:image toRect:rect];
}
答案 0 :(得分:4)
+ (UIImage *)captureView:(UIScrollView *)view inContentRect:(CGRect)rect{
UIImage* image = nil;
CGPoint savedContentOffset = view.contentOffset;
CGRect savedFrame = view.frame;
UIGraphicsBeginImageContextWithOptions(view.contentSize, 1, 0);
view.contentOffset = CGPointZero;
view.frame = CGRectMake(0, 0, view.contentSize.width, view.contentSize.height);
[view.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
view.contentOffset = savedContentOffset;
view.frame = savedFrame;
UIGraphicsEndImageContext();
// after all of this, crop image to needed size
return [Utils cropImage:image toRect:rect];
}
答案 1 :(得分:2)
您必须使用contentSize.height
来获取tableview的高度
试试这个
UIGraphicsBeginImageContext(self.tableView.contentSize.height);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = image1;
答案 2 :(得分:0)
是的,你可以这样做。我不能提供你想要的工作代码,我可以指导你如何做到这一点。在循环中,您必须通过更改它的contentOffset
来渲染表的所有部分,并将每个图像放在数组中。获得表视图的所有部分后,必须将表的各个部分连接到一个图像(在cgimagecontext中绘制每个图像,记住为结果图像设置正确的大小)。就是这样,它不是那么难:)希望这会有所帮助,祝你好运!