CGContextDrawPDFPage taking up large amounts of memory

后端 未结 2 717
Happy的楠姐
Happy的楠姐 2020-12-01 08:52

I have a PDF file that I want to draw in outline form. I want to draw the first several pages on the document each in their own UIImage to use on a button so that when clic

相关标签:
2条回答
  • 2020-12-01 09:05

    Take a look at my code for a PDF image slicer on github:

    http://github.com/luciuskwok/Maps-Slicer

    There should be enough memory on the device that a 13 MB allocation isn't going to kill the app. Are you draining the autorelease pool each time you render a PDF? You might also want to cache the rendering into a UIImage so that it doesn't have to render it every time it's displayed.

    0 讨论(0)
  • 2020-12-01 09:10

    Try to add :

    CGContextSetInterpolationQuality(g, kCGInterpolationHigh);
    CGContextSetRenderingIntent(g, kCGRenderingIntentDefault); 
    

    before :

    CGContextDrawPDFPage(g, m_page);
    

    I had a similar issue and adding the 2 function call above resulted in the rendering using 5x less memory. Might be a bug in the CGContextXXX drawing functions

    0 讨论(0)
提交回复
热议问题