1

我想在背景图像上绘图,什么时候我会擦除该绘图然后只擦除绘图而不是背景图像?我怎样才能实现该任务。通过此代码,我的背景图像也被擦除。

   ` UITouch *touch = [touches anyObject];
    previousPoint2 = previousPoint1;
    previousPoint1 = [touch previousLocationInView:self.view];
    currentPoint = [touch locationInView:self.view];

    CGPoint mid1 = midPoint(previousPoint1, previousPoint2);
    CGPoint mid2 = midPoint(currentPoint, previousPoint1);

    UIGraphicsBeginImageContext(imageDoodle.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();


    [imageDoodle.image drawInRect:CGRectMake(0, 0, imageDoodle.frame.size.width, imageDoodle.frame.size.height)];


    CGContextMoveToPoint(context, mid1.x, mid1.y);


    CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);

    CGContextSetLineCap(context, kCGLineCapRound);

     if(IsErase)
    {
    CGContextSetBlendMode(context,kCGBlendModeClear);
    }

    else
    {
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redvalue, greenvalue, bluevalue, 1.0);
    }

    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 8.0);


    CGContextStrokePath(UIGraphicsGetCurrentContext());

     imageDoodle.image = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();

}

`

4

2 回答 2

0

添加another UIImageView到您的 imageDoodle

//Add outer ImgView for Drawing purpose
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,imageDoodle.frame.size.width, imageDoodle.frame.size.height)];
imgView.userInteractionEnabled  = YES;
imgView.multipleTouchEnabled = YES;
[imageDoodle addSubview:imgView];

编辑:现在使用相同的代码,但imgView用于drawing purpose

[imgView.image drawInRect:CGRectMake(0, 0, imageDoodle.frame.size.width, imageDoodle.frame.size.height)];

设置当前图像imgView

imgView.image = UIGraphicsGetImageFromCurrentImageContext();

现在original image用 main设置你的ImageView

现在render主要ImageView得到backgroundimage+drawing

于 2013-01-18T08:34:30.830 回答
0

将透明 UIView 添加到您的 ImageView 并将其高度和宽度按比例分配给 imageView 或 imagesize。无论你想画什么,在 uiview 中画并擦除它。

于 2013-01-18T09:08:03.910 回答