I'm developing an application on which user can pinch and rotate the the image. After pinching and rotating the image. the image must be print. I want to get the scaling factor and rotating factor of my image so that I can draw a new image and then print that new image. But my problem is I cant get the scaling and rotating factor of my image. Can anybody teach me on how to get the scaling factor and rotate factor using CGAffineTransform. Or can anybody teach me on how to save the image after scaling and rotating. thank you so much guys. here is my code.
- (void)rotationImage:(UIRotationGestureRecognizer*)gesture {
[self.view bringSubviewToFront:gesture.view];
if ([gesture state] == UIGestureRecognizerStateEnded) {
lastRotation = 0;
return;
}
CGAffineTransform currentTransform = img_tempImage.transform;
CGFloat rotation = 0.0 - (lastRotation - gesture.rotation);
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation);
img_tempImage.transform = newTransform;
myTransform = img_tempImage.transform;
lastRotation = gesture.rotation;
isTransform = YES;
}
- (void)pinchImage:(UIPinchGestureRecognizer*)pinchGestureRecognizer {
[self.view bringSubviewToFront:pinchGestureRecognizer.view];
pinchGestureRecognizer.view.transform = CGAffineTransformScale(pinchGestureRecognizer.view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
pinchGestureRecognizer.scale = 1;
myTransform = img_tempImage.transform;
isTransform = YES;
}
- (void)panpan:(UIPanGestureRecognizer *)sender {
[self.view bringSubviewToFront:img_tempImage];
CGPoint translation = [sender translationInView:self.view];
CGPoint imageViewPosition = img_tempImage.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;
myPoint = imageViewPosition;
img_tempImage.center = imageViewPosition;
[sender setTranslation:CGPointZero inView:self.view];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
I found the answer on my question on how to get the scale and rotate value.
CGFloat angle = [(NSNumber *)[img_tempImage valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
NSLog(@"by angle: %.2f",angle);
CGFloat xScale = img_tempImage.transform.a;
CGFloat yScale = img_tempImage.transform.d;
NSLog(@"xScale :%.2f",xScale);
NSLog(@"yScale :%.2f",yScale);