La tâche: créer une image à partir d'un fichier PDF comme aperçu rapide pour mon PDF affiché avec le CATiledLayer
(plus lent, plus haute résolution). Problème: Je reçois très rapidement un message d'erreur sur mon iPad "Avertissement de la mémoire reçue Niveau = 1" et peu après "Avertissement de la mémoire reçue Niveau = 2" ... puis l'application plante.iOS: Obtenir "Avertissement de la mémoire reçue" après l'utilisation de l'image créée à partir du PDF et utilisée comme arrière-plan
- (void) drawSinglePage:(CALayer *)layer inContext:(CGContextRef)ctx {
CGContextSaveGState(ctx);
CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
@synchronized(self) {
// Draw PDF for HighRes
CGPDFPageRef page = CGPDFDocumentGetPage(page1, 1);
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
CGFloat scaleRatio = 960/pageRect.size.height;
CGFloat yOffset = ((960-pageRect.size.height)/scaleRatio)+960;
CGContextTranslateCTM(ctx, -(layer.bounds.size.width-pageRect.size.width)/2, yOffset);
CGContextScaleCTM(ctx, scaleRatio, -scaleRatio);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, layer.bounds, 0, true));
CGContextDrawPDFPage(ctx, page);
// Draw Background-Image as fast preview (PROBLEM HERE!!)
UIGraphicsBeginImageContext(layer.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGRect prob = CGContextGetClipBoundingBox(context);
CGContextFillRect(context, prob);
CGContextSaveGState(context);
CGContextSetInterpolationQuality(context, kCGInterpolationLow);
CGContextTranslateCTM(context, -(layer.bounds.size.width-pageRect.size.width)/2, yOffset);
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, CGRectMake(0.0, 0.0, layer.bounds.size.width, layer.bounds.size.height), 0, true));
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
UIImage *back = UIGraphicsGetImageFromCurrentImageContext();
NSData *jpegDataFile = UIImageJPEGRepresentation(back, 0.2f);
UIImage *smBack = [[UIImage alloc] initWithData:jpegDataFile];
UIGraphicsEndImageContext();
// Now set the subview
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:smBack];
backgroundImageView.frame = CGRectMake(0.0, 0.0, smBack.size.width, smBack.size.height);
backgroundImageView.contentMode = UIViewContentModeTopLeft;
backgroundImageView.opaque = YES;
[self.view addSubview:backgroundImageView];
[self.view sendSubviewToBack:backgroundImageView];
[backgroundImageView release];
}
CGContextRestoreGState(ctx);
}
}
Note: si je ne mets pas la vue de l'image de fond tout est ok - donc assez sûr que je dois sortir quelque chose, mais je tout essayé. En ce moment je n'ai aucune idée. Remarque: le "CGPDFDocumentRelease(page1)
" sera appelé dans la fonction - (void)dealloc
de ce ViewController.