2010-01-22 26 views
0

我在PDF上繪製圖像時遇到問題。我將縮放,旋轉,移動等應用於圖像並在PDF上繪製該圖像。但繪圖不正確輸出。當我旋轉圖像時,它只是縮放而不旋轉。在PDF上的圖像繪製無法繪製圖像的轉換和輸出錯誤

在這裏,我將更詳細地解釋: 我在UIWebView上放置一個圖像,使圖像完全在PDF上產生假效果。然後,在製作PDF時,我在UIWebView上的PDF上繪製圖像。

但是,當我去準備帶有已應用大量轉換的修改圖像的PDF時,圖像縮放不會旋轉。

這裏,img_copyright是一個繼承UIImageView的自定義類。

CGFloat orgY = (newY-whiteSpace)+img_copyright.frame.size.height; 
CGFloat modY = pageRect.size.height-orgY; 

CGFloat orgX = img_copyright.frame.origin.x-PDF_PAGE_PADDING_WIDTH; 
CGFloat modX = orgX; 

//We're getting X,Y of the image here to decide where to put the image on PDF. 


CGRect drawRect = CGRectMake (modX, modY, img_copyright.frame.size.width, img_copyright.frame.size.height); 

//Preparing the rectangle in which image is to be drawn. 


CGContextDrawImage(pdfContext, drawRect, [img_copyright.image CGImage]); 
    [img_copyright release]; 

// Actually drawing the image. 

但是,當我看到PDF圖像沒有正確繪製到它。

你會有什麼建議,是基於X,Y的圖像繪製問題嗎? 如果我們不依賴X,Y,我們如何決定將圖像放在PDF上? 在旋轉,縮放的PDF上繪製圖像的確切方法是什麼?

當我將圖像插入到UIWebView的滾動條上時,圖像。 http://www.freeimagehosting.net/ 「>

當我繪製圖像到PDF形象。
http://www.freeimagehosting.net/」>

+0

你好everyonce ,請對這個問題發表評論。我也想要可能性。我知道圖像可以在pdf上旋轉繪製,但我沒有固定的位置,位置是動態的,我從圖像本身得到x/y座標。所以,如果我與圖像中心合作會不會好? – 2010-01-25 05:43:53

回答

1
CGFloat angleInRadians =-1*Angle* (M_PI/180.0); 
CGAffineTransform transform=CGAffineTransformIdentity; 

transform = CGAffineTransformMakeRotation(angleInRadians); 
//transform = CGAffineTransformMakeScale(1, -1); 
//transform =CGAffineTransformMakeTranslation(0,80); 

CGRect rotatedRect = CGRectApplyAffineTransform(CGRectMake(0,0,Image.size.width,Image.size.height), transform); 

UIGraphicsBeginImageContext(rotatedRect.size); 
//[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0,rotatedRect.size.height); 
CGContextScaleCTM(UIGraphicsGetCurrentContext(),1, -1); 

//CGContextTranslateCTM(UIGraphicsGetCurrentContext(), +(rotatedRect.size.width/2),+(rotatedRect.size.height/2)); 

CGContextTranslateCTM(UIGraphicsGetCurrentContext(), (rotatedRect.origin.x)*-1,(rotatedRect.origin.y)*-1); 
CGContextRotateCTM(UIGraphicsGetCurrentContext(), angleInRadians); 
//CGContextTranslateCTM(UIGraphicsGetCurrentContext(), -(rotatedRect.size.width/2),-(rotatedRect.size.height/2)); 

CGImageRef temp = [Image CGImage]; 

CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, Image.size.width,Image.size.height), temp); 

//CGContextRotateCTM(UIGraphicsGetCurrentContext(), -angleInRadians); 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

return viewImage; 
+0

謝謝老兄...很高興有你的迴應...應用程序現在有進步..! – 2010-02-06 12:57:52