我正在开发一个用户可以捏合并旋转图像的应用程序。捏合并旋转图像后。图像必须打印。我想得到我的图像的缩放因子和旋转因子,以便我可以绘制一个新图像,然后打印该新图像。但我的问题是我无法获得图像的缩放和旋转因子。任何人都可以教我如何使用CGAffineTransform获得缩放因子和旋转因子。或者任何人都可以教我如何在缩放和旋转后保存图像。十分感谢大家。这是我的代码。
- (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;
}
答案 0 :(得分:3)
我在如何获得比例和旋转值的问题上找到了答案。
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);