目前我正在制作“传统”屏幕截图,并使用图形编辑器将它们组合起来以立即显示完整的网页。有没有更有效的方法来制作整个网页的屏幕截图,就像使用Google Chrome的Awesome Screenshot一样?
(不,我没有 iPhone;)
目前我正在制作“传统”屏幕截图,并使用图形编辑器将它们组合起来以立即显示完整的网页。有没有更有效的方法来制作整个网页的屏幕截图,就像使用Google Chrome的Awesome Screenshot一样?
(不,我没有 iPhone;)
请参阅下面的代码。
-(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
}
我从这个链接得到这个代码。希望它会帮助你。
你必须自己写。
webView
。我相信这是一种最简单的方法,可以在模拟器上运行。