cgpdfpageref转uiimage
宋涵忍
2023-12-01
-(UIImage *)cgUIimage:(CGPDFPageRef)pageRef
{
CGRect pageRect = CGPDFPageGetBoxRect(pageRef, kCGPDFMediaBox);
UIGraphicsBeginImageContext(pageRect.size);
CGContextRef imgContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(imgContext);
CGContextTranslateCTM(imgContext, 0.0, pageRect.size.height);
CGContextScaleCTM(imgContext, 1.0, -1.0);
CGContextSetInterpolationQuality(imgContext, kCGInterpolationDefault);
CGContextSetRenderingIntent(imgContext, kCGRenderingIntentDefault);
CGContextDrawPDFPage(imgContext, pageRef);
CGContextRestoreGState(imgContext);
UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
return tempImage;
}