【发布时间】:2014-01-03 19:40:24
【问题描述】:
目前我正在制作“传统”屏幕截图,并使用图形编辑器将它们组合起来以一次显示完整的网页。有没有更有效的方法来截取整个网页,就像使用谷歌浏览器的Awesome Screenshot 一样?
(不,我没有 iPhone;)
【问题讨论】:
标签: ios iphone objective-c ios-simulator webpage-screenshot
目前我正在制作“传统”屏幕截图,并使用图形编辑器将它们组合起来以一次显示完整的网页。有没有更有效的方法来截取整个网页,就像使用谷歌浏览器的Awesome Screenshot 一样?
(不,我没有 iPhone;)
【问题讨论】:
标签: ios iphone objective-c ios-simulator webpage-screenshot
你必须自己写。
webView。我相信这是最简单的方法,可以在模拟器上运行。
【讨论】:
请看下面的代码。
-(NSData *)getImageFromView:(UIView *)view // Mine is UIWebView but should work for any
{
NSData *pngImg;
CGFloat max, scale = 1.0;
CGSize viewSize = [view bounds].size;
// Get the size of the the FULL Content, not just the bit that is visible
CGSize size = [view sizeThatFits:CGSizeZero];
// Scale down if on iPad to something more reasonable
max = (viewSize.width > viewSize.height) ? viewSize.width : viewSize.height;
if( max > 960 )
scale = 960/max;
UIGraphicsBeginImageContextWithOptions( size, YES, scale );
// Set the view to the FULL size of the content.
[view setFrame: CGRectMake(0, 0, size.width, size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
pngImg = UIImagePNGRepresentation( UIGraphicsGetImageFromCurrentImageContext() );
UIGraphicsEndImageContext();
return pngImg; // Voila an image of the ENTIRE CONTENT, not just visible bit
}
我从this 链接获得此代码。希望对你有帮助。
【讨论】: