在 PDF 上绘制图像无法绘制经过变换的图像并且输出错误

发布于 2024-08-18 09:40:07 字数 1194 浏览 9 评论 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/">

I've a problem with drawing images on PDF. I do apply scaling, rotation, move, etc. to an image and draws that image on the PDF. But drawing is not outputting correctly. When I do rotate image, it just scales and doesn't rotate.

Here, I explain in more detail:
I place an image on UIWebView to make fake effect of image exactly on PDF. Then, I do draw image on PDF which is on the UIWebView while making PDF.

But when I go and prepare PDF with modified image, which has been applied lots of transformations, image scales not rotates.

Here, img_copyright is a Custom class inheriting 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.

But when i see the PDF image is not properly drawn into it.

What would you suggest, is it the problem due to image drawing based on its X,Y?
How could we decide where to put the image on PDF if we don't depend on X, Y?
What is the exact method of drawing image on PDF with rotation, scale?

The Image when I do insert the image onto UIWebView's scrollbar.
http://www.freeimagehosting.net/">

The Image when I do draw the image onto PDF.
http://www.freeimagehosting.net/">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有木有妳兜一样 2024-08-25 09:40:07
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;
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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文