我有一个网页视图,我正在尝试打印,当我加载一个很长(超过一页)的网页时,它打印出所有黑色。我无法使用renderInContext方法,因为当我尝试打印页面时因为高内存问题而导致应用程序崩溃。我正在使用dymo收据打印机。
这是我的代码
+ (UIImage*)viewToImage:(UIView*)theView
{
UIImage *image = nil;
// Save current bounds so we can reset them laster
CGRect tmpFrame = theView.frame;
CGRect tmpBounds = theView.bounds;
// Adjust the bounds of the webview so we can take a screen shot of the entire view, even if its scrolled off screen.
CGRect aFrame = theView.bounds;
aFrame.size.width = theView.frame.size.width;
aFrame.size.height = theView.frame.size.height;
theView.frame = aFrame;
aFrame.size.height = [theView sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
theView.frame = aFrame;
UIGraphicsBeginImageContextWithOptions(theView.bounds.size, NO, 1.8);
[theView drawViewHierarchyInRect:theView.bounds afterScreenUpdates:YES];
// crashes the app [self.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}