0

我在 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/">

4

1 回答 1

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;
于 2010-02-03T10:04:52.037 回答