【发布时间】:2014-09-04 11:57:22
【问题描述】:
我正在使用这里的代码How can I programmatically put together some UIImages to have one big UIImage? 将多个屏幕截图组合成一个大的垂直图像。但是,我在调用此函数以将多个图像组合在一起时遇到问题:
imageContainer = [UIImage imageByCombiningImage:imageContainer withImage:viewImage];
如何调用这个 UIImage+combine 类别来将图片库合并在一起?
这是我的代码:
- (void) printScreen {
// this is a method that starts the screenshot taking process
// this line is necessary to capture the completion of the scrollView animation
_webView.scrollView.delegate = self;
// save the first image
UIGraphicsBeginImageContextWithOptions(_webView.bounds.size, NO, 0);
[_webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
// scroll to the next section
[_webView.scrollView scrollRectToVisible:CGRectMake(0, _webView.frame.size.height, _webView.frame.size.width, _webView.frame.size.height) animated:YES];
}
- (void )scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
// at this point the _webView scrolled to the next section
// I save the offset to make the code a little easier to read
CGFloat offset = _webView.scrollView.contentOffset.y;
UIGraphicsBeginImageContextWithOptions(_webView.bounds.size, NO, 0);
// note that the below line will not work if you replace _webView.layer with _webView.scrollView.layer
[_webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
// if we are not done yet, scroll to next section
if (offset < _webView.scrollView.contentSize.height) {
[_webView.scrollView scrollRectToVisible:CGRectMake(0, _webView.frame.size.height+offset, _webView.frame.size.width, _webView.frame.size.height) animated:YES];
}
UIImage *image = [UIImage imageByCombiningImage:image1 withImage:image2];
[[self theNewImageView] setImage:image];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
NSLog(@"%@ printScreen Image", image);
NSLog(@"%@ printScreen Image2", image2);
}
编辑:
在这一点上,我尝试了很多不同的东西。我是 Objective C 开发的新手,所以我一直在深入研究 Apple 开发人员文档和其他好地方,以获取 stack 和 lynda 等信息。 我从日志中看到两个不同的代码:printScreen Image2、printScreen Image,但我无法获得调用新类别的函数。
我可以将所有图像单独写入相册,我可以将 image1 或 image2 合并为一个图像,但不能将两个图像或所有图像合并。
【问题讨论】:
-
有什么问题?提供更多细节。
-
我可以从“scrollViewDidEndScrollingAnimation”中调用“UIImage+combine”函数还是应该创建一个新函数?
标签: ios