iOS截取长图,自定义截取size
之前做过在查看商品详情时,需要截取很长的图片进行分享,已经超出一屏幕的显示范围:
- (UIImage *)captureScrollView:(UIScrollView *)scrollView { UIImage *image = nil; UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, NO, 0.0); { CGPoint savedContentOffset = scrollView.contentOffset; CGRect savedFrame = scrollView.frame; scrollView.frame = CGRectMake(0 , 0, scrollView.contentSize.width, scrollView.contentSize.height); [scrollView.layer renderInContext:UIGraphicsGetCurrentContext()]; image = UIGraphicsGetImageFromCurrentImageContext(); scrollView.contentOffset = savedContentOffset; scrollView.frame = savedFrame; } UIGraphicsEndImageContext(); if (image != nil) { return image; } return nil; }