在Gestures旋转相同图像后,CoreGraphics删除图像的问题?

时间:2012-12-10 15:47:26

标签: iphone objective-c image core-graphics uigesturerecognizer

目前,我遇到了一个有点危险的问题。我正在做的是借助核心图形擦除图像并在同一图像上应用旋转效果。当我只是擦除图像时,擦除工作正常,但是当我首先旋转该图像然后擦除相同的图像。当我正在移动以擦除图像的任何特定像素时,图像变得模糊并且图像的高度正在减小。这是我用来擦除图像的代码片段: -

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
        UITouch *touch = [[event allTouches] anyObject];
        mPreviousPoints = [touch locationInView:self];
        mPreviousPoints.y = mPreviousPoints.y ;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

        UITouch *touch = [[event allTouches] anyObject];
        CGPoint currentPoint = [touch locationInView:self];
        currentPoint.y = currentPoint.y ;

        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        UIGraphicsBeginImageContext(self.frame.size);
        CGContextRef currentContext = UIGraphicsGetCurrentContext();
        [self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        CGContextSetBlendMode(currentContext,kCGBlendModeClear);
        CGContextSetLineCap(currentContext, kCGLineCapRound);
        CGContextSetLineWidth(currentContext, 20);
        CGContextSetStrokeColorWithColor(currentContext, [[UIColor clearColor] CGColor]);
        CGContextBeginPath(currentContext);
        CGContextMoveToPoint(currentContext, mPreviousPoints.x , mPreviousPoints.y );
        CGContextAddLineToPoint(currentContext, currentPoint.x , currentPoint.y);
        CGContextStrokePath(currentContext) ;
        self.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
}

如果我不旋转图像,代码工作正常。

我试图用触摸事件旋转图像但是没有变化,所以这里是我在我的应用程序中使用的滚动代码: -

#pragma mark Rotation Gesture

- (void)rotateImage:(UIRotationGestureRecognizer *)recognizer
{
if (objAppDelegate.touchBool == YES)
{
    if([recognizer state] == UIGestureRecognizerStateEnded)
    {
        previousRotation = 0.0;
        return;
    }

    CGFloat newRotation = 0.0 - (previousRotation - [recognizer rotation]);

    CGAffineTransform currentTransformation = touchImageView.transform;
    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);

    touchImageView.transform = newTransform;

    previousRotation = [recognizer rotation];
}
}

我发布截图,以便您可以正确理解我的问题。所以,请看看它并帮助我。

Original Image

Image after applying erase effect only

Image after rotation

Image after rotation and erasing

如果可以,请帮助我!

提前致谢:)

0 个答案:

没有答案