简体   繁体   English

Android-跟踪要绘制的实时触摸事件

[英]Android - Tracking Real-Time Touch Events to Draw

I need your help. 我需要你的帮助。

I am trying to implement a paint system with live-tracking, you may think: “Live-tracking? 我正在尝试通过实时跟踪实现绘画系统,您可能会认为:“实时跟踪? What do you mean?” 你什么意思?”

So I am implementing a solution to track each touch movement on the display, so I can decide, if I want to paint on a specific spot or not, this decision must be in real-time, right when the user touches the display. 因此,我正在实施一种解决方案来跟踪显示器上的每个触摸运动,因此我可以决定是否要在特定位置上绘画,这个决定必须是实时的,就在用户触摸显示器时。

There will be some images where the user should paint the inner white space inside of the respective shape; 在某些图像中,用户应绘制相应形状内部的内部空白; figure 1 shows an example of this shape. 图1显示了这种形状的示例。

图1

The user should paint the inside of the shape in a specific direction/order; 用户应按特定的方向/顺序绘制形状的内部; I still don't know how I can configure this order/direction in the image. 我仍然不知道如何在图像中配置此顺序/方向。 An example of a specific order would be like the one showing on figure 2. 一个特定顺序的示例类似于图2所示。

图2

So I want the user to paint starting from the zone 1 to the zone 6, do you understand? 因此,我希望用户从区域1到区域6进行绘画,您知道吗? I don't want the user to be able to paint the zone 1 and then zone 3, without painting the zone 2 first… 我不希望用户先绘制区域1然后再绘制区域3,而无需先绘制区域2 ...

In the end, I would have the shape filled, like the figure 3 shows. 最后,我将填充形状,如图3所示。 The arrows are there just to show the right direction of drawing. 箭头仅用于显示正确的绘制方向。

图3

It's not just about direction, the specific spots on the image matter, there will be different types of images, and I can't use only the direction. 这不仅与方向有关,而且图像上的特定点也很重要,会有不同类型的图像,我不能仅使用方向。

How can I determine the specific spots in an image with a specific order to be painted? 如何确定具有特定绘制顺序的图像中的特定斑点?

The only idea that came to my mind, would be some kind of training mode, where I (the developer) would draw the image with the order I want, and the system behind would create virtual points on the code, with a small distance between each of them. 我想到的唯一想法是某种训练模式,在这种模式下,我(开发人员)将以所需的顺序绘制图像,而背后的系统将在代码上创建虚拟点,并且它们之间的距离很小他们每个人。 Then I would have an array with all the “spots” saved with the order I draw them, do you understand? 然后,我将得到一个数组,其中所有“斑点”都按照我绘制它们的顺序保存了,您知道吗?

I don't know if this will work, and if it will be fast enough to travel my array of “spots” when the user is trying to draw on the image? 我不知道这是否行得通,并且当用户尝试在图像上绘制图像时,它是否足够快地移动我的“斑点”阵列? Because I want this to work on real-time, the system should check if it's a valid spot to draw right when the user touches the display… 因为我想让它实时工作,所以系统应该检查用户触摸显示器时是否是正确绘制的有效点…

Do you think it will work? 您认为这行得通吗? Do you have some recommendations about this? 您对此有何建议? What are the best structures and stuff like that? 最好的结构和东西是什么? I am not asking for written code, I just need some guidelines. 我不要求书面代码,我只需要一些准则。

I think I explained my problem well, if you have any question please ask me. 我想我很好地解释了我的问题,如果您有任何疑问,请问我。

Thank you very much in advance! 提前非常感谢您!

if all your shapes are lines you can treat the points you want your users to "touch" as squares, every time an ACTION_MOVE event is happening, check if the finger is touching the next point. 如果所有形状都是直线,则可以将希望用户“触摸”的点视为正方形,每次发生ACTION_MOVE事件时,请检查手指是否触摸了下一个点。 You can make the size of the squares whatever suits you, like 48dp or 92dp or the width/height of the shape you are drawing. 您可以根据自己的需要设置正方形的大小,例如48dp或92dp或要绘制的形状的宽度/高度。

You said you don't want any code so I assume you know how to do this (if not reply and I will post code too). 您说您不需要任何代码,因此我假设您知道如何执行此操作(如果不答复,我也将发布代码)。

Also you didn't mention what happens if the user goes out of the shape, if you want the user to continue drawing until they lift their finger then this way is good, when the ACTION_UP event happens check if the last point is touched (assuming it can only be touched if all others are touched like explained above). 另外,您也没有提到如果用户走出形状会发生什么,如果您希望用户继续绘图直到他们松开手指,那么这种方式很好,当ACTION_UP事件发生时检查是否触摸了最后一点(假设只有如上文所述触摸其他所有对象时才能触摸它)。

Here is an image if you'd like to have a visual guide: 如果您需要视觉指导,请使用以下图片: 在此处输入图片说明

Obviously if you it this way you have to calculate the positions of each point you will have, I doubt there is any way to automate this. 显然,如果采用这种方式,则必须计算每个点的位置,我怀疑是否有任何方法可以使这种方式自动化。

If you need any more help or you need some code please reply and I will post some! 如果您需要更多帮助或需要一些代码,请回复,我将发布一些信息! :D :d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM