iOS截图

1.普通的截图办法,在View上面截图

/**
* 截图代码
*
* @param view 需要截图的view
* @param rect 需要截取的区域
*
* @return 返回截取的对象
*/
+ (UIImage *)viewSnapshot:(UIView *)view withInRect:(CGRect)rect
{ UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,rect);
image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return image;
}

2.截取UIScrollView的ContentSize的全部区域,包括未显示的部分,将UIScrollView传递进去

/**
* UIScrollView从顶截到底
*
* @param scrollView 需要呗截图的UIScrollView
*
* @return 返回UIScrollView的ContentSize的截图
*/
+ (UIImage *)screenShot:(UIScrollView *)scrollView{
UIImage *image = nil;
UIGraphicsBeginImageContext(scrollView.contentSize);
{
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect savedFrame = scrollView.frame;
scrollView.contentOffset = CGPointZero;
scrollView.frame = CGRectMake(, , scrollView.contentSize.width, scrollView.contentSize.height);
[scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
scrollView.contentOffset = savedContentOffset;
scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext(); if (image != nil) {
NSLog(@"截图成功!");
} return image;
}
上一篇:hibernate 使用C3P0数据源


下一篇:(转) android里,addContentView()动态增加view控件,并实现控件的顶部,中间,底部布局