我的代码如下。我得到的错误

断言失败:(s-> stack-> next!= NULL),函数CGGStackRestore,文件Context/CGGStack.c,第116行。

代码:

 CGPDFPageRef page = CGPDFDocumentGetPage(document, i+1);
            CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
            CGFloat pdfScale = width/pageRect.size.width;
            pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
            pageRect.origin = CGPointZero;
            UIGraphicsBeginImageContext(pageRect.size);
            CGContextRef context = UIGraphicsGetCurrentContext();

            // White BG  CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);  CGContextFillRect(context,pageRect);   CGContextSaveGState(context);

            CGContextTranslateCTM(context, 0.0, pageRect.size.height);
            CGContextScaleCTM(context, 1.0, -1.0);
            CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, pageRect, 0, true));
            CGContextDrawPDFPage(context, page);
            CGContextRestoreGState(context);

            UIImage *thm = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            NSLog(@"Image %@",thm);
            pdfImage = [[UIImageView alloc] initWithImage:thm];
            NSLog(@"Image View: %@",pdfImage);
            [self.view addSubview:pdfImage];
            [self.view reloadInputViews
];

请帮忙。

最佳答案

CGContextSaveGState之前没有CGContextRestoreGState!

10-08 12:32