Maximum screenshot size (memory buffer)

the entire code block consists of the following:

CGSize layerSize = [webview sizeThatFits:CGSizeZero]; if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f) { UIGraphicsBeginImageContextWithOptions(layerSize, NO, 2.0f); } else { UIGraphicsBeginImageContext(layerSize); } [webview.layer renderInContext:UIGraphicsGetCurrentContext()]; screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

but after testing this line causes a problem: [webview.layer renderInContext: UIGraphicsGetCurrentContext ()];

looks like memory loss, is there a maximum size (width x height) based on the device (ipod, iphone, ipad) where this function worked - seems to crash for very long pages on the retina screen?

+4
source share
3 answers

I do not think the memory issue is causing your problem. You must take a screenshot using void UIGraphicsBeginImageContextWithOptions(CGSize size,BOOL opaque,CGFloat scale); . The last parameter set to 0.0 will take care of the problem of the retina / non-retina.

"The scale factor applied to the bitmap. If you specify a value of 0.0, the scale factor will be set to the scale factor of the deviceโ€™s main screen." From the documentation .

 UIGraphicsBeginImageContextWithOptions(webview.bounds.size, YES, 0.0); [webview.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

EDIT: you say your application is still crashing.

Is it possible that you forgot to add the QuartzCore framework .

You also need to import the QuartzCore header :

 #import <QuartzCore/QuartzCore.h> 

from Technical Q & A QA1703 (Screen capture in UIKit applications)

0
source

Hi akishnani. I had the same problem. After I was suffering and looking for everything that I just discovered that I overestimated the (void)drawRect:(CGRect)rect method and it created the problem, it can solve the problem if it has not been solved yet.

 -(void)drawRect:(CGRect)rect { [super drawRect:rect]; } 
0
source

This is a fairly old thread, but a screen height limitation has been detected.

I have specified the upper limit (4000 CGFloat), and if the content I have to make the screenshot exceeds this, I crop the screenshot in the upper limit.

This helped me reduce the recurrence of a memory error.

0
source

Source: https://habr.com/ru/post/1401430/


All Articles