我有一个方法用于从我的iOS应用程序中的各个视图中获取图像,以便让用户通过电子邮件发送屏幕。大多数绘制屏幕的屏幕都能正常工作,但是当我在UIWebView上使用此技术时,我只能获得屏幕的可见部分。屏幕外的任何内容都不包含在渲染的图像中。我在Stack上搜索了一番,但到目前为止还没有找到解决办法?!
这是我目前使用的方法:
-(NSData *)getImageFromView:(UIView *)view
{
NSData *pngImg;
CGFloat max, scale = 1.0;
CGSize size = [view bounds].size;
// Scale down larger images else we run into mem issues with mail widget
max = (size.width > size.height) ? size.width : size.height;
if( max > 960 )
scale = 960/max;
UIGraphicsBeginImageContextWithOptions( size, YES, scale );
CGContextRef context = UIGraphicsGetCurrentContext();
[view.layer renderInContext:context];
pngImg = UIImagePNGRepresentation( UIGraphicsGetImageFromCurrentImageContext() );
UIGraphicsEndImageContext();
return pngImg;
}