0

添付画像をご覧ください。ユーザーが複数の画像で描画できるアプリを作成しましたが、描画を消去するために Clear Color を使用すると、消去されたパスの周りに黒い境界線が表示されます。描画には UIBezierPath を使用しました。これは UIBezierPath の問題ですか、それとも他の方法で解決できますか? コードスニペットが必要な場合はお知らせください。ここに投稿します。

ここに画像の説明を入力

編集:コードが追加されました!関係のないコードは無視してください。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(isFirstTapp)
    {
        isFirstTapp=NO;
        [self.spooleteView removeHandView];
    }
    isdraw=YES;
    mouseSwapped=NO;
    UITouch *touch = [touches anyObject];
    lastPoint=[touch locationInView:self];

    //UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [currentPath moveToPoint:p];
    currentPath.flatness = 10.0;

    NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
    UIBezierPath *myPath=[[UIBezierPath alloc]init];



    myPath.lineCapStyle=kCGLineJoinRound;
    [dict setObject:myPath forKey:@"Path"];
    colorTag= [[AppHelper userDefaultsForKey:@"ColorTag"]intValue];

    self.selectedColor = [brushColor objectAtIndex:colorTag];

    if(isErase)
    {
        myPath.lineWidth=30.0;
        self.selectedColor = [UIColor whiteColor];

    }
    else
    {
        if([mode isEqualToString:@"morsecode"])
            myPath.lineWidth=10.0;
        else
            myPath.lineWidth=5.0;
    }

    //[dict setObject:[brushColor objectAtIndex:colorTag] forKey:@"Colors"];
    [dict setObject:self.selectedColor forKey:@"Colors"];

    [myArr addObject:dict];
    currentPath=myPath;
    currentPath.flatness = 0.1;
    currentPath.lineJoinStyle = kCGLineJoinRound;
    currentDict=dict;
    [myPath moveToPoint:lastPoint];
    [myPath release];
    [dict release];    
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(!istapped)
    {
        if([mode isEqualToString:@"morsecode"])
        {
            mouseSwapped=YES;
            UITouch *mytouch=[[touches allObjects] objectAtIndex:0];

            currentPoint=[mytouch locationInView:self];

            [currentPath addLineToPoint:currentPoint];

            [self setNeedsDisplay];
        }
    }

//    UITouch *touch = [touches anyObject];
//    CGPoint p = [touch locationInView:self];
//    [currentPath addLineToPoint:p];
//    [self setNeedsDisplay];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(!istapped)
    {
        mouseSwapped=YES;

        UITouch *objTouch=[[touches allObjects] objectAtIndex:0];

        if (!mouseSwapped&&(objTouch.tapCount==1))
        {
            lastPoint=currentPoint;
        }
    }

    if(isErase)
    {
        if ([myArr count]>50)
        {
            [myArr removeAllObjects];
        }
    }

    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [currentPath addLineToPoint:p];
    [self drawBitmap]; // (3)
    [self setNeedsDisplay];
    [currentPath removeAllPoints]; //(4)
}

- (void)drawRect:(CGRect)rect
{
    [self.incrementalImage drawInRect:rect]; // (3)
    [currentPath stroke];

    //[self.incrementalImage drawInRect:rect];

    for (NSMutableDictionary *dictionary in myArr)
    {
        UIBezierPath *_path = [dictionary objectForKey:@"Path"];

        self.selectedColor = [dictionary objectForKey:@"Colors"];
        [self.selectedColor setStroke];
        [_path stroke];

        [_path strokeWithBlendMode:kCGBlendModeCopy alpha:1.0];
        _path.lineCapStyle = kCGLineJoinRound;

        if([mode isEqualToString:@"morsecode"])
        {
            if (!isErase)
            {
                const float p[2] = {1,15.9};
                [_path setLineDash:p count:2 phase:0.9];
            }

            else
            {
                self.selectedColor = [UIColor whiteColor];
            }
        }
    }
}

- (void)drawBitmap // (3)
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

    [self.selectedColor setStroke];

    if (!self.incrementalImage) // first draw; paint background white by ...
    {
        UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds]; // enclosing bitmap by a rectangle defined by another UIBezierPath object
        [[UIColor clearColor] setFill];
        [rectpath fill]; // filling it with white
    }

    [self.incrementalImage drawAtPoint:CGPointZero];
    [currentPath stroke];
    self.incrementalImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}
4

1 に答える 1

0

私はその問題の理由を見つけました。以下の関数の2行目が原因でした。

- (void)drawRect:(CGRect)rect
{
    [self.incrementalImage drawInRect:rect]; // (3)
    [currentPath stroke];

つまり、[currentPath stroke]; コメントしましたが、パスの周りに黒い境界線がなくなりました。これが他の人に役立つことを願っています。

于 2013-02-17T23:40:08.843 に答える