2

現在、私は少し危険な問題で立ち往生しています。私がやっていることは、コアグラフィックスの助けを借りて画像を消去し、その同じ画像に回転効果を適用することです. 画像を消去するだけでは消去は正確に機能しますが、最初にその画像を回転させてから同じ画像を消去すると。画像の特定のピクセルを消去するために移動しているため、画像がぼやけ、画像の高さが減少しています。画像を消去するために使用しているコードスニペットは次のとおりです:-

- (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];
}
}

私の問題を正しく理解できるように、スクリーンショットを投稿しています。だから、それを見て、私を助けてください。

元の画像

消しゴム効果のみ適用後の画像

回転後の画像

回転・消去後の画像

できれば助けてください!

前もって感謝します :)

4

0 に答える 0