1

我使用别人的捏手势代码进行缩放,效果很好,但它在我的照片编辑应用程序中缩放我的图像,一旦用户按下完成缩放,我需要反映和保存更改,或者以另一种方式说我需要图像如果有人使用捏来缩放,实际上会被放大和裁剪。我想我可以使用他们缩放的数量 * uigraphicsbeginimagecontext 的帧大小,但该策略不起作用,因为当用户缩放图像并点击完成按钮时,图像被保存得更小,因为现在这个非常大的尺寸被挤压到视图中当我真正想要它剪掉任何剩菜而不做任何拟合时。

- (IBAction)pinchGest:(UIPinchGestureRecognizer *)sender{


if (sender.state == UIGestureRecognizerStateEnded
    || sender.state == UIGestureRecognizerStateChanged) {
    NSLog(@"sender.scale = %f", sender.scale);

    CGFloat currentScale = self.activeImageView.frame.size.width / self.activeImageView.bounds.size.width;
    CGFloat newScale = currentScale * sender.scale;

    if (newScale < .5) {
        newScale = .5;
    }
    if (newScale > 4) {
        newScale = 4;
    }

    CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale);
    self.activeImageView.transform = transform;
    scalersOfficialChange = newScale;
    sender.scale = 1;

}
}

- (IBAction)doneMoverViewButtonPressed:(UIButton *)sender {
// turn off ability to move & scale
moverViewActive = NO;

NSLog(@"%f %f",dragOfficialChange.x,dragOfficialChange.y);
NSLog(@"%f",rotationOfficialChange);
NSLog(@"%f",scalersOfficialChange);


//problem area below...
CGSize newSize = CGSizeMake(self.activeImageView.bounds.size.width * scalersOfficialChange, self.activeImageView.bounds.size.height * scalersOfficialChange );

UIGraphicsBeginImageContext(newSize);

[self.activeImageView.image drawInRect:CGRectMake(dragOfficialChange.x, dragOfficialChange.y, self.layerContainerView.bounds.size.width, self.layerContainerView.bounds.size.height)];

self.activeImageView.image = UIGraphicsGetImageFromCurrentImageContext();


UIGraphicsEndImageContext();

[self hideMoveViewerAnimation];

//resets activeimageview coords
CGRect myFrame = self.layerContainerView.bounds;
myFrame.origin.x = 0;
myFrame.origin.y = 0;
self.activeImageView.frame = myFrame;

//reset changes values
dragOfficialChange.x = 0;
dragOfficialChange.y = 0;
rotationOfficialChange = 0;
scalersOfficialChange = 0;

}
4

1 回答 1

0

首先,你能把你的问题说得更清楚吗?我建议你想把你的图像画成一个矩形并且不想挤压它,对吗?

然后让我们试试这个方法:

//The method: drawInRect:(CGRect) will scale your pic and squeeze it to fit the Rect area
//So if you dont want to scale your pic, you can use the method below
[image drawAsPatternInRect:(CGRect)_rect];
//This method would not scale your image and cut the needless part
于 2013-06-21T15:52:37.077 回答