2011-11-11 2 views
3

내 응용 프로그램에서 PDF 리더를 만들고 있습니다. 성능을 맞추기 위해 기본 스케일로 뷰를 그립니다. 이보기는 CATiledLayer 기반이 아닙니다. 사용자가 약간 확대하면이 뷰를 CATiledLayer로 오버레이하여 일반적인 사용 사례에서 훨씬 선명한 이미지와 메모리 사용량을 제공합니다.Blurry PDF Drawing with CATiledLayer

이제 문제는 기본 상태 (CALayer보기가 표시 될 때)에서 이미지가 약간 흐려지는 것입니다. 그냥 약간의 확대를 시도하고 CATiledLayer가 실행되면 동일한 텍스트와 모든 것이 선명 해집니다. 여기

은 (그것이 있어야로 선명한 이미지와 텍스트 표시)를 CATiledLayer보기에 대한 코드입니다 : 여기
- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context{ 

    CGPDFPageRef drawPDFPageRef = NULL; 
    CGPDFDocumentRef drawPDFDocRef = NULL; 

    @synchronized(self) { 
     if (_PDFDocRef==nil) { 
      NSLog(@"PDF NIL"); 
      _PDFDocRef = [SharedPDFDocRef sharedInstanceForUrl:_fileURL andPhrase:_password]; 
      _PDFPageRef = CGPDFDocumentGetPage(_PDFDocRef, _page); 
     } 
     drawPDFDocRef = _PDFDocRef; 
     drawPDFPageRef = _PDFPageRef; 
    } 

    if (drawPDFPageRef != NULL) { 
     CGContextTranslateCTM(context, 0.0f, self.bounds.size.height); 
     CGContextScaleCTM(context, 1.0f, -1.0f); 

     CGAffineTransform transform = 
     CGPDFPageGetDrawingTransform(drawPDFPageRef, kCGPDFCropBox, layer.bounds, 0, true); 

     CGContextConcatCTM(context, transform); 

     CGContextSetRenderingIntent(context, kCGRenderingIntentDefault); 
     CGContextSetInterpolationQuality(context, kCGInterpolationDefault); 

     CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); 
     CGContextFillRect(context, CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFBleedBox)); 

     CGContextDrawPDFPage(context, drawPDFPageRef); 
    } 

    //CGPDFPageRelease(drawPDFPageRef); CGPDFDocumentRelease(drawPDFDocRef);  
} 

가 기본보기에 대한 코드의을 (괜찮 표시되지만 이미지는 동일한 품질로하지 않습니다 CATiledLayer one) :

- (void) drawRect:(CGRect)rect { 
    [super drawRect:rect]; 
    CGPDFPageRef drawPDFPageRef = NULL; 
    CGPDFDocumentRef drawPDFDocRef = NULL; 

    @synchronized(self) { 
     drawPDFDocRef = CGPDFDocumentRetain(_PDFDocRef); 
     drawPDFPageRef = CGPDFPageRetain(_PDFPageRef); 
    } 
    // get the page reference 
    CGPDFPageRef page = drawPDFPageRef; 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    // white background 

    // transformation/-lation 
    CGContextTranslateCTM(context, 0.0, self.bounds.size.height); 
    CGContextScaleCTM(context, 1.00f, -1.00f); 
    CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page, 
                  kCGPDFCropBox, self.bounds, 0, true)); 

    CGContextSetInterpolationQuality(context, kCGInterpolationDefault); 
    CGContextSetRenderingIntent(context, kCGRenderingIntentDefault); 


    CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f); 
    CGContextFillRect(context, CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFBleedBox)); 

    CGContextDrawPDFPage(context, page); 
    CGPDFPageRelease(drawPDFPageRef); 
    CGPDFDocumentRelease(drawPDFDocRef); 

} 

답변

1

확대/축소를 수행 한 후에보기의 콘텐츠 배율 인수를 설정하려고 시도 했습니까? 당신의 UIScrollViewDelegate에서

당신이 할 것 :

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale 
{ 
    [view setContentScaleFactor:scale]; 
}