uiimageview 上的透明度应显示图像 [重复]
Posted
技术标签:
【中文标题】uiimageview 上的透明度应显示图像 [重复]【英文标题】:transparency on uiimageview should show image [duplicate] 【发布时间】:2012-09-08 10:01:00 【问题描述】:可能重复:How to draw a transparent stroke (or anyway clear part of an image) on the iPhone
我有一个透明层的 uiimage 视图 如果我们触摸那个透明层,应该擦除部分透明层并显示它的背面..我该怎么做....? 提前致谢
【问题讨论】:
What have you tried? UIImage * backgroundImage = [UIImage imageNamed:@"images.jpeg"]; CALayer* aLayer = [CALayer 层]; CGFloat nativeWidth = CGImageGetWidth(backgroundImage.CGImage); CGFloat nativeHeight = CGImageGetHeight(backgroundImage.CGImage); CGRect startFrame = CGRectMake(0.0, 0.0, nativeWidth, nativeHeight); aLayer.contents = (id)backgroundImage.CGImage; aLayer.frame = startFrame; [self.view.layer addSublayer:aLayer]; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ; @pammu 你想从源图像中删除所选图像的位吗? 我有一个图像,上面有一个覆盖图像,当我删除覆盖时,它应该显示图像的一部分 【参考方案1】:据我了解,您想通过触摸来擦除图像的一部分... 是对的吗 ?
试试这个代码,通过触摸移动部分图像来擦除......
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
lastTouch = [touch locationInView:canvasView];
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:canvasView];
CGFloat brushSize = 35;
CGColorRef strokeColor = [UIColor whiteColor].CGColor;
UIGraphicsBeginImageContext(scratchView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[canvasView.image drawInRect:CGRectMake(0, 0, canvasView.frame.size.width, canvasView.frame.size.height)];
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, brushSize);
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
CGContextStrokePath(context);
canvasView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastTouch = [touch locationInView:canvasView];
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
希望对你有帮助....
【讨论】:
以上是关于uiimageview 上的透明度应显示图像 [重复]的主要内容,如果未能解决你的问题,请参考以下文章