Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS SDK - how to screen shot content of tableView?

How to screen-shot ALL content of tableView? (all content = visible are + NOT visible area)

I tried this:

UIGraphicsBeginImageContext(self.tableView.bounds.size);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.imageView.image = image1;

but it doesn't work, I mean it's screenshot only visible area :(


I solved it :))

here is the code :)

+ (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];                                 
}
like image 754
arturdev Avatar asked Sep 03 '13 11:09

arturdev


1 Answers

+ (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];                                 
}
like image 156
arturdev Avatar answered Oct 15 '22 18:10

arturdev