在 iPhone 模拟器中打印文本手势

发布于 2025-01-01 14:29:27 字数 3082 浏览 0 评论 0原文

我是 iPhone 开发新手,

我想打印用户在屏幕上写的任何内容,我在项目中使用了手势,

查看我的屏幕截图,

在第一张图片中没有任何内容,所以我想打印输入的符号不正确 在第二张图片中,我在屏幕上写了 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();
    }
}

当用户双击屏幕图像时,屏幕图像将被清除,我在开始时将其写在触摸开始和触摸结束方法中。

我该如何实施?

提前致谢!!

i am new to iPhone development,

i want to print whatever user writes on the screen, i used gesture in my project,

see my screen shot,

in first image there is nothing, so i want to print Entered symbol is not incorrect
in second image i wrote A in screen so i want to print you selected: A

screenshot
screenshot
here is a code snippet..

declaration in .h file

    CGPoint lastPoint;
    UIImageView *drawImage;
    BOOL mouseSwiped;   
    int mouseMoved;

code in .m file

- (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();
    }
}

when user double tapes the screen image will be cleared, i written this inside touches begin and touches end method at very start.

HOW CAN I IMPLEMENT THIS ?

Thanks In Advance !!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅倚清风 2025-01-08 14:29:27

好吧,你选择了一个相当雄心勃勃的项目。

您可能想查看Tessaect,尽管编译它需要一些工作对于电话。

还有袖珍 OCR

然后是AABBY

Well, you've chosen a rather ambitious project.

You might want to check out the Tessarect although it will take some work to even compile it for the phone.

There's also Pocket OCR.

Then there is AABBY.

泪眸﹌ 2025-01-08 14:29:27

一个简单的方法是标准化字母的大小,只是为了使您的代码更容易,然后您可能必须建立字体或参考点。举例来说,要么获取用户的每个字母的示例,要么建立一种“字体”,以便用户尝试模仿这些字母。如果您这样做,获得结果的最佳方法是使用已识别字母与参考文献的相关系数。

不仅仅是相关系数,您可能还需要运行一些过滤器,首先使图像变成黑白,因为这可能是最简单的方法,然后您必须分离正方形(子矩阵) )每个对应一个字母,然后重新调整其大小或根据您的参考进行调整,以便您可以计算相关系数并确定它是什么字母。

这是一个相当复杂的事情。我不知道已经为 iOS 开发了什么,但这只是我如何在另一个平台上做到这一点的简要描述。祝你好运,请务必查看信号处理论坛以获得专家的帮助。

这篇文章可能可以更详细地为您提供总体思路的提示。 智能交通系统应用的车牌识别算法

An easy way to go is to standardize the size of your letters, just to make your code easier, then you would probably have to establish a font or a reference point. Say for example either you get an example of every letter of your user or you establish a "font", so that the user tries to imitate those letters. If you do that the best way to get results is by using the correlation coefficient of the identified letters with your references.

There is more than just the correlation coefficient, you also will probably have to run a few filters, first to make your image just black and white, because that's probably the easiest way to go, then you would have to separate squares (sub-matrixes) each corresponding to one letter and then re-sizing it or adjusting it to your references so that you can calculate the correlation coefficient and determine what letter it is.

This is a rather complex thing to talk about. I don't know what's already developed for the iOS but that's just a brief description on how I did this in another platform. Good luck and be sure to check the Signal Processing Forum for some help of the experts.

This article can probably give you a hint of the general idea in a much more detailed way. A License Plate-Recognition Algorithm for Intelligent Transportation System Applications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文