2010-07-14 52 views
2

確定,所以這裏是我想做的事:如何擴大含CGContextDrawPDFPage在可可觸摸繪製的基於矢量的圖形一個PDF

  • 負載包含矢量圖形
  • 將其放大PDF文件
  • 它繪製到圖形上下文
  • 從結果中創建一個UIImage並將其顯示

一切工作正常,但事實該圖形失去質量和像素化外觀:(

這裏就是縮放發生代碼:

// PDF loaded before 
CGPDFPageRef page = CGPDFDocumentGetPage (document, 1); 

UIGraphicsBeginImageContext(CGSizeMake(width, height)); 

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(context); 

CGRect rect = CGPDFPageGetBoxRect(page, kCGPDFCropBox); 
float widthFactor = width/ rect.size.width; 
float heightFactor = height/ rect.size.height; 
CGAffineTransform pdfTransform2 = CGAffineTransformMakeScale (widthFactor, heightFactor); 
CGContextConcatCTM(context, pdfTransform2); 

CGContextDrawPDFPage(context, page); 
CGContextRestoreGState(context); 

retValue = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

我認爲問題是,我只能重新調整的背景下,而不是實際的PDF。有沒有其他方式可以做到這一點,而不會有質量損失?

非常感謝您的任何提示!

+1

你有沒有想過這個? – Kalle 2010-08-30 19:27:50

回答

0

這又是我,誰問的問題是:只使用一個規模

CGAffineTransform pdfTransform2 = CGAffineTransformMakeScale (widthFactor, heightFactor); 

嘗試。我無法恢復我的帳戶,所以我創建了一個新的...

好的這裏的答案:搜索示例項目的Xcode文檔稱爲ZoomingPDFViewer。它包含您需要的一切縮放PDF文檔而不會造成質量損失。

+1

如果您在[meta](http://meta.stackoverflow.com/)上提問,可能會幫助您恢復舊帳戶;或者,我可以將您的舊帳戶合併到此帳戶中。 @如果你想要合併,我會回來。 – Will 2011-03-24 13:08:29

+0

謝謝你的方式,我可以恢復我的帳戶:) – 2012-01-04 12:52:10

0

您可能會搞亂圖像的比例。即,當你與規模:

CGAffineTransform pdfTransform2 = CGAffineTransformMakeScale (widthFactor, widthFactor);