在CA Tiled图层中渲染pdf页面时崩溃

时间:2011-11-11 12:12:21

标签: iphone ios xcode ipad

我试图在CGContext上渲染pdf页面,方法是将它们转换为图像,然后在平铺图层中渲染它们。该应用程序在模拟器上运行良好,但在特定pdf页面的设备上崩溃。在ontruments上运行应用程序时,它似乎消耗了大量内存。

之前在这个平台上有很多问题已经尝试了所有的解决方案,但问题仍然存在。请在下面找到代码。它总是在调用CGContextDrawPDFPage

时崩溃
 CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
    pdfScale = self.frame.size.width/pageRect.size.width;
    originalPdfScale = 2 * pdfScale;
    //pdfScale = 1.39444;
    pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);


    //---Create a low res image representation of the PDF page to display before the TiledPDFView renders its content---
    UIGraphicsBeginImageContext(pageRect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    //---First fill the background with white---
    CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
    CGContextFillRect(context,pageRect);
    NSLog(@"context = %@ :::: pdfScale = %f ::::: page=%@ ", context, pdfScale, page );
    CGContextSaveGState(context);
    //---Flip the context so that the PDF page is rendered right side up---
    CGContextTranslateCTM(context, 0.0, pageRect.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    //---Scale the context so that the PDF page is rendered at the correct size for the zoom level---
    CGContextScaleCTM(context, pdfScale,pdfScale);  
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
    CGContextSetRenderingIntent(context, kCGRenderingIntentDefault); 
    CGContextDrawPDFPage(context, page);
    CGContextRestoreGState(context);

    UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    if (backgroundImageView) {
        [backgroundImageView removeFromSuperview];
        [backgroundImageView release];
        backgroundImageView = nil;
    }
    backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
    backgroundImageView.frame = pageRect;
    backgroundImageView.userInteractionEnabled =YES;
    backgroundImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:backgroundImageView];
    [self sendSubviewToBack:backgroundImageView];


    // Create the TiledPDFView based on the size of the PDF page and scale it to fit the view.
    if (pdfView) {
        [pdfView removeFromSuperview];
        [pdfView release];
        pdfView = nil;
    }
    pdfView = [[ProM_TiledPDFView alloc] initWithFrame:pageRect andScale:pdfScale];
    [pdfView setPage:page];

    [self addSubview:pdfView];
    [backgroundImage release];

0 个答案:

没有答案