gpt4 book ai didi

ios - 清除 UIImageView 触摸绘制的内容

转载 作者:行者123 更新时间:2023-11-29 11:11:49 25 4
gpt4 key购买 nike

我有继承自 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 按钮,如何清除 Canvas 的上下文但保留 background.png 作为背景,只删除用户使用触摸绘制的内容(我有属性 Canvas )?

最佳答案

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

CoreGraphics: Image Transparent Background

关于ios - 清除 UIImageView 触摸绘制的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11215299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com