从Path对象获取坐标(根本没有这样的方法)

时间:2023-01-05 21:19:53

How do I get coordianates from Path and/or Region objects in Android? There are no such methods which allow you to do that.

如何从Android中的Path和/或Region对象获取coordianates?没有这样的方法可以让你这样做。

Basically I just need the coordinates of my figure points which my Path object contains.

基本上我只需要我的Path对象包含的图形点的坐标。

Maybe I can can accomplish this via Reflection? Any help would be appreciated.

也许我可以通过反思实现这一目标?任何帮助,将不胜感激。

2 个解决方案

#1


0  

If we look at the source code for Path:

如果我们查看Path的源代码:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/Path.java?av=f

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/Path.java?av=f

We can see that the coordinates are not stored on Path and are passed into native calls.

我们可以看到坐标不存储在Path上并传递给本机调用。

One workaround would be to extend Path and override all relevant methods (lineTo, quadTo, moveTo, etc.) to keep track of the coordinates yourself.

一种解决方法是扩展Path并覆盖所有相关方法(lineTo,quadTo,moveTo等)以自己跟踪坐标。

#2


0  

Well. Maybe if you use Path's getBounds method and save result in a rect object, you can access on 'left' and 'top' property field of that object for retrieving x and y coordinates

好。也许如果您使用Path的getBounds方法并将结果保存在rect对象中,您可以访问该对象的“left”和“top”属性字段以检索x和y坐标

#1


0  

If we look at the source code for Path:

如果我们查看Path的源代码:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/Path.java?av=f

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/graphics/Path.java?av=f

We can see that the coordinates are not stored on Path and are passed into native calls.

我们可以看到坐标不存储在Path上并传递给本机调用。

One workaround would be to extend Path and override all relevant methods (lineTo, quadTo, moveTo, etc.) to keep track of the coordinates yourself.

一种解决方法是扩展Path并覆盖所有相关方法(lineTo,quadTo,moveTo等)以自己跟踪坐标。

#2


0  

Well. Maybe if you use Path's getBounds method and save result in a rect object, you can access on 'left' and 'top' property field of that object for retrieving x and y coordinates

好。也许如果您使用Path的getBounds方法并将结果保存在rect对象中,您可以访问该对象的“left”和“top”属性字段以检索x和y坐标