views:

343

answers:

2

I'm having problems with drawing rotated images on PDF, my output is worse.

My case is, we don't know have any fixed co-ordinates. X,Y, rotation, etc. depends on ImageView itself. I select the ImageView and rotate it through Sliders.

Check on ZOSH application. I need to implement functionalities like that app. I want to make PDF by adding images one by one.

Please send me link for any example that can help me out, I'm stuck here. I'm drawing the image on PDF based on center of the imageview.

Please help me, Thank You.

A: 

The answer is in Apple's documentation. Listings 13-3 and 13-4 seems like what you are after.

Johan Kool
A: 

Was having the same problem,after a fair amount of time i was able to find a solution....might be helpful to you

-(UIImage*)RotateImage:(UIImage*)Image :(float)Angle { 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();

//[viewImage autorelease];


return viewImage;

}

for Zooming issues....i suggest you try to make a subclass for the application window

I found this web page that shows how to subclass the application window so as to observe taps and forward those taps to the view controller.

http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/

Hope that helps you...

krunal
Why subclass `UIWindow` (the application window) to add support for zooming? That should be handled in an `UIView`, most likely an `UIImageView` inside an `UIScrollView` in this case. What difficulty did you encounter that you had to resort to subclassing `UIWindow`?
Johan Kool
Well there was problem that image goes to the left upper corner of the screen..so to retain the position of the image have to subclass UIWindow,so the image remains at the same position and image also zoom accordingly...
krunal