[英]print text gesture in iPhone simulator
我是iPhone开发新手,
我想打印任何用户在屏幕上写的内容,我在我的项目中使用了手势,
看我的屏幕截图,
在第一个图像没有任何东西,所以我想打印Entered symbol is not incorrect
的第二个图像我在屏幕上写了A
所以我想打印you selected: A
这是一个代码片段..
.h文件中的声明
CGPoint lastPoint;
UIImageView *drawImage;
BOOL mouseSwiped;
int mouseMoved;
.m文件中的代码
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
drawImage.image = nil;
return;
}
lastPoint = [touch locationInView:self.view];
lastPoint.y -= 20;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
drawImage.image = nil;
return;
}
if(!mouseSwiped) {
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
当用户双重磁带时,屏幕图像将被清除,我写入内部触摸开始并触摸结束方法。
我该如何实施?
提前致谢 !!
一个简单的方法是标准化字母的大小,只是为了使代码更容易,然后你可能需要建立一个字体或参考点。 比如说,要么得到用户的每个字母的示例,要么建立“字体”,以便用户尝试模仿这些字母。 如果这样做,获得结果的最佳方法是使用已识别字母与引用的相关系数。
不仅仅是相关系数,你可能还需要运行一些滤镜,首先要使你的图像只是黑白,因为这可能是最简单的方法,那么你必须分开正方形(子矩阵) )每个字母对应一个字母,然后重新调整大小或将其调整为您的参考,以便您可以计算相关系数并确定它是什么字母。
这是一个相当复杂的事情。 我不知道iOS已经开发了什么,但这只是我在另一个平台上如何做到这一点的简要描述。 祝你好运,一定要查看信号处理论坛 ,寻求专家的帮助。
本文可能会以更详细的方式向您提供一般概念的提示。 智能交通系统应用的车牌识别算法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.