【发布时间】:2014-01-05 02:48:37
【问题描述】:
我已经为 pdf 文件创建了缩略图。所以每当用户单击任何一个缩略图时,它都应该全屏显示。所以我使用 UIImageView 来显示它。问题是。而不是显示
但它的显示是这样的,不清楚....
我用来显示的代码是
(void) displayPdf
{
CGFloat width = 60.0;
NSLog(@"%d",i);
//UIImage* thumbnailImage;
NSLog(@"%@",fileName);
// NSString*fileName= @"2_slo_sample";
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pdf"];
NSURL* pdfFileUrl = [NSURL fileURLWithPath:path];
CGPDFPageRef page;
CGRect pageRect = CGRectMake(0, 0, 150,150);
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();
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfFileUrl);
//NSUInteger totalNum = CGPDFDocumentGetNumberOfPages(pdf);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, pageRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetGrayFillColor(context, 1.0, 1.0);
CGContextFillRect(context, pageRect);
// Grab the first PDF page
page = CGPDFDocumentGetPage(pdf, i);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, pageRect, 0, false);
// And apply the transform.
CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, pageRect, 0, true));
CGContextDrawPDFPage(context, page);
// Create the new UIImage from the context
thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGPDFDocumentRelease(pdf);
//webView.hidden = YES;
imageView1 = [[UIImageView alloc] init];
imageView1.frame =CGRectMake(0, 50, 280, 280);
[imageView1 setContentMode:UIViewContentModeScaleAspectFit];
[imageView1 setNeedsDisplay];
imageView1.backgroundColor = [UIColor clearColor];
[imageView1 setUserInteractionEnabled:YES];
imageView1.image = thumbnailImage;
[self.view addSubview:imageView1];
}
请帮助我,以便我可以清楚地显示它。
提前致谢
【问题讨论】:
标签: ios iphone objective-c uiimage pdf-generation