/**
截取滚动视图的长图片(如tableview等)
@param scroller 滚动视图
@return 截取的长图
*/
+ (UIImage *)captureImageLonge:(UIScrollView*)scroller{
//(1)截取长图
UIImage* image = nil;
UIGraphicsBeginImageContextWithOptions(scroller.contentSize, YES, 0.0);
//保存collectionView当前的偏移量
CGPoint savedContentOffset = scroller.contentOffset;
CGRect saveFrame = scroller.frame;
//将collectionView的偏移量设置为(0,0)
scroller.contentOffset = CGPointZero;
scroller.frame = CGRectMake(0, 0, scroller.contentSize.width, scroller.contentSize.height);
//在当前上下文中渲染出collectionView
[scroller.layer renderInContext: UIGraphicsGetCurrentContext()];
//截取当前上下文生成Image
image = UIGraphicsGetImageFromCurrentImageContext();
//恢复collectionView的偏移量
scroller.contentOffset = savedContentOffset;
scroller.frame = saveFrame;
UIGraphicsEndImageContext();
if (image != nil) {
//(2)保存到本地相册
ALAssetsLibrary * library = [ALAssetsLibrary new];
NSData * data = UIImageJPEGRepresentation(image, 1.0);
[library writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
if(!error){
//顶部状态栏提醒
[JDStatusBarNotification showJDStatusBar:@"截屏成功,已为你保存到相册"];
}else{
//顶部状态栏提醒
[JDStatusBarNotification showJDStatusBar:@"抱歉,截屏失败"];
}
}];
return image;
}else {
return nil;
}
}