gpt4 book ai didi

iphone - 核心图形 : Using finger strokes to erase part of image?

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:54 26 4
gpt4 key购买 nike

我正在编写代码来删除图像的一部分。我不是 CoreGraphics 方面的专家,需要一些帮助。

这个例程工作正常,但是,当快速移动时,它会失去接触(不是很流畅)。是否可以修改此例程以使 CGContextClearRect 更平滑?有没有更好、更快的方法来做到这一点?

-(void)drawRect:(CGRect)rect {

if (!myDrawing) { // touchpoints stored here
myDrawing = [[NSMutableArray alloc] initWithCapacity:0];
}
UIGraphicsBeginImageContext(frontImage.frame.size);
[frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)];

if ([myDrawing count] > 0) {
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5);
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);

for (int i = 0 ; i < [myDrawing count] ; i++) {
NSArray *thisArray = [myDrawing objectAtIndex:i];

if ([thisArray count] > 2) {
float thisX = [[thisArray objectAtIndex:0] floatValue];
float thisY = [[thisArray objectAtIndex:1] floatValue];
CGContextBeginPath(UIGraphicsGetCurrentContext());

for (int j = 2; j < [thisArray count] ; j+=2) {
thisX = [[thisArray objectAtIndex:j] floatValue];
thisY = [[thisArray objectAtIndex:j+1] floatValue];

CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(thisX, thisY, 10, 10));
}
}
}

}
frontImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

}
iOS Simulator

最佳答案

您不必使用 CGContextClearRect 来清除笔划。

而是执行 CGContextSetBlendMode(context, kCGBlendModeClear)

此调用更改了颜色混合模式,使绘图操作将清除位图而不是使用颜色进行绘图。

然后你可以只画连接触摸位置的线,这样就没有间隙了。

要切换回正常渲染,请执行 CGContextSetBlendMode(context, kCGBlendModeNormal)

使用不同的混合模式会很有帮助。

关于iphone - 核心图形 : Using finger strokes to erase part of image?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5808244/

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