views:

474

answers:

1

Hello guys,

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. [url=http://www.freeimagehosting.net/][img]http://www.freeimagehosting.net/uploads/3f90741a97.jpg[/img][/url]

The Image when I do draw the image onto PDF. [url=http://www.freeimagehosting.net/][img]http://www.freeimagehosting.net/uploads/ff0255a62a.jpg[/img][/url]

+1  A: 

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;

krunal
thanks dude... it's good to have your response... the app has progress now..!
MobiHunterz