绘图时在图像上方正确使用橡皮擦工具?

时间:2015-04-14 17:17:45

标签: ios iphone drawing

我有一个UIView,因为我有画图。在这个视图我是画笔工具,矩形工具和更新新图像和绘图。就像ACEDrawingView

一样

我面临着橡皮擦工具的一个问题。当我使用橡皮擦时,背景图像的颜色也消失了。请查看屏幕截图。

enter image description here

在上图中,黑色部分是笔画,白色部分是我的橡皮画。用户做橡皮擦时不想清除背景图像。只是绘图。

重绘图片代码

    - (void)updateCacheImage:(BOOL)redraw
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);
    if (redraw) {
        // erase the previous image
        self.image = nil;

        // load previous image (if returning to screen)
        [[self.prev_image copy] drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

        // I need to redraw all the lines
        for (id<ACEDrawingTool> tool in self.pathArray) {
            [tool draw];
        }

    } else {
        // set the draw point
        [self.image drawAtPoint:CGPointZero];
        [self.currentTool draw];
    }

    // store the image
    self.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

橡皮擦工具图纸

    - (void)draw
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextAddPath(context, self.path);
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, self.lineWidth);
    CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    CGContextSetAlpha(context, self.lineAlpha);
    CGContextStrokePath(context);
}

2 个答案:

答案 0 :(得分:0)

这是因为您正在使用@Entity @Table(name="Projektstati") public class Projektstati implements Serializable{ @ManagedProperty("#{sessionBean}") private SessionBean sessionBean; public void setSessionBean(SessionBean sessionBean){this.sessionBean = sessionBean;} ,我猜这是最后选择的颜色,在这种情况下是白色。尝试使用self.lineColor.CGColor替换当前颜色,并添加以下代码行[UIColor clearColor]

答案 1 :(得分:0)

我现在面对这个问题......刚刚找到了类似下面的解决方案。你的橡皮擦颜色应该就像你的背景视图背景颜色。

例如:   CGContextSetStrokeColorWithColor(context,yourviewBackgroundColor);

相关问题