相关疑难解决方法(0)

CGContextDrawPDFPage占用大量内存

我有一个PDF文件,我想以大纲形式绘制.我想在他们自己的UIImage中绘制文档中的前几页,以便在按钮上使用,这样当单击时,主显示将导航到单击的页面.

但是,CGContextDrawPDFPage在尝试绘制页面时似乎使用了大量内存.尽管图像应该只有100px左右,但应用程序崩溃时特别是绘制一个页面,根据Instruments,它只为一页分配大约13 MB的内存.

这是绘图的代码:

//Note: This is always called in a background thread, but the autorelease pool is setup elsewhere
+ (void) drawPage:(CGPDFPageRef)m_page inRect:(CGRect)rect inContext:(CGContextRef) g { 
    CGPDFBox box = kCGPDFMediaBox;
    CGAffineTransform t = CGPDFPageGetDrawingTransform(m_page, box, rect, 0,YES);
    CGRect pageRect = CGPDFPageGetBoxRect(m_page, box);

    //Start the drawing
    CGContextSaveGState(g);

    //Clip to our bounding box
    CGContextClipToRect(g, pageRect);   

    //Now we have to flip the origin to top-left instead of bottom left
    //First: flip y-axix
    CGContextScaleCTM(g, 1, -1);
    //Second: move origin
    CGContextTranslateCTM(g, 0, -rect.size.height);

    //Now …
Run Code Online (Sandbox Code Playgroud)

pdf iphone cocoa-touch core-graphics

9
推荐指数
1
解决办法
6840
查看次数

CGContextDrawPDFPage内存泄漏 - 应用程序崩溃

当我用Instruments分析我的应用程序时,我发现分配的数据CGContextDrawPDFPage不会立即释放.应用程序因为崩溃而崩溃CGContextDrawPDFPage.

在此输入图像描述

在此输入图像描述

你好,这是我在CATiledlayer中绘制pdf的代码

      - (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context
    {
    if (_PDFPageRef == nil) {
        return;
    }
    CGPDFPageRef drawPDFPageRef = NULL;
    CGPDFDocumentRef drawPDFDocRef = NULL;

    @synchronized(self) // Briefly block main thread
    {
        drawPDFDocRef = CGPDFDocumentRetain(_PDFDocRef);
        if( _PDFPageRef != (__bridge CGPDFPageRef)([NSNull null]) )
            drawPDFPageRef = CGPDFPageRetain(_PDFPageRef);
        else
            return;
    }

    //CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 0.0f);
    //CGContextFillRect(context, CGContextGetClipBoundingBox(context));

    if (drawPDFPageRef != NULL) // Render the page into the context
    {
        CGFloat boundsHeight = viewBounds.size.height;

        if (CGPDFPageGetRotationAngle(drawPDFPageRef) == 0)
        {
            CGFloat boundsWidth = …
Run Code Online (Sandbox Code Playgroud)

iphone xcode pdfrenderer ios pdf-rendering

9
推荐指数
1
解决办法
853
查看次数