【问题标题】:Clear UIImageView what is drawn with touch清除 UIImageView 触摸绘制的内容
【发布时间】:2012-06-26 20:17:53
【问题描述】:

我有继承自 UIImageView 的类 Canvas(在背景设置为图像 background.png),并且在方法 touchesMoved 中我绘制了某种颜色的手势:

UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self];  

UIGraphicsBeginImageContext(self.frame.size); 
CGContextRef ctx = UIGraphicsGetCurrentContext();  

[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, width);
CGContextSetRGBStrokeColor(ctx, red, green, blue, alpha);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

location = currentLocation;

我有下面的 ERASE 按钮,如何清除画布的上下文但将 background.png 保留为背景,只删除用户通过触摸绘制的内容(我有属性画布)?

【问题讨论】:

    标签: ios ios5 uiimageview


    【解决方案1】:

    您可以在图像视图上绘制一个透明矩形,如下所示:

    CoreGraphics: Image Transparent Background

    【讨论】:

      猜你喜欢
      • 2016-05-16
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多