gpt4 book ai didi

ios - 识别使用贝塞尔路径绘制的文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:59 25 4
gpt4 key购买 nike

我编写了以下代码,用于使用贝塞尔路径绘制文本。
现在我的任务是我们如何识别使用 Beizer 路径绘制的文本。
例如,如果我画“苹果”,那么我的标签将显示“你画了苹果”。

@implementation NaiveVarWidthView
{
UIBezierPath *path;
UIImage *incrementalImage;
CGPoint pts[5];
uint ctr;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setMultipleTouchEnabled:NO];
path = [UIBezierPath bezierPath];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
ctr = 0;
UITouch *touch = [touches anyObject];
pts[0] = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
ctr++;
pts[ctr] = p;
if (ctr == 4)
{
pts[3] = CGPointMake((pts[2].x + pts[4].x)/2.0, (pts[2].y + pts[4].y)/2.0);
[path moveToPoint:pts[0]];
[path addCurveToPoint:pts[3] controlPoint1:pts[1] controlPoint2:pts[2]];
UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0); //
if (!incrementalImage)
{
UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds];
[[UIColor whiteColor] setFill];
[rectpath fill];
}
[incrementalImage drawAtPoint:CGPointZero];
[[UIColor blackColor] setStroke];
float speed = 0.0;
for (int i = 0; i < 3; i++)
{
float dx = pts[i+1].x - pts[i].x;
float dy = pts[i+1].y - pts[i].y;
speed += sqrtf(dx * dx + dy * dy);
}
#define FUDGE_FACTOR 100
float width = FUDGE_FACTOR/speed;
[path setLineWidth:width];
[path stroke];
incrementalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self setNeedsDisplay];
[path removeAllPoints];
pts[0] = pts[3];
pts[1] = pts[4];
ctr = 1;
}
}
- (void)drawRect:(CGRect)rect
{
[incrementalImage drawInRect:rect];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setNeedsDisplay];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEnded:touches withEvent:event];
}
@end

最佳答案

我不确定您是否有兴趣使用开源代码,但您可以尝试一下 GLGestureRecognizer .

这是对您在 stack-Overflow 中的问题的一个这样的回答。

关于ios - 识别使用贝塞尔路径绘制的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20536030/

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