A question about region

zhanghui

Member
Licensed User
Longtime User
I have a question in graphics programming, for example, draw a polygen, how to decide whether the touch is in the polygen or not.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
See this discussion: graphics - Point in Polygon aka hit test - Stack Overflow

A possible simple solution (which actually delegates the problem to the native graphics code):
1. Create a Path object that follows the polygon sides.
2. Use Canvas.ClipPath to limits the drawings to the polygon.
3. Fill the polygon using Canvas.DrawRect with a color that is slightly different than the background.

When the user touches the screen you should check Canvas.Bitmap.GetPixel and find the point color. The color will tell you whether this point is inside or outside the polygon.

Note that you should first check the value of a known inner-point to find the actual color value, as it might change.
 
Upvote 0

zhanghui

Member
Licensed User
Longtime User
Thanks

See this discussion: graphics - Point in Polygon aka hit test - Stack Overflow

A possible simple solution (which actually delegates the problem to the native graphics code):
1. Create a Path object that follows the polygon sides.
2. Use Canvas.ClipPath to limits the drawings to the polygon.
3. Fill the polygon using Canvas.DrawRect with a color that is slightly different than the background.

When the user touches the screen you should check Canvas.Bitmap.GetPixel and find the point color. The color will tell you whether this point is inside or outside the polygon.

Note that you should first check the value of a known inner-point to find the actual color value, as it might change.


Thank Erel very much for your kindly reply.
 
Upvote 0

Similar Threads

D
  • Question
Replies
4
Views
849
D
  • Question
Android Question Question about the widget
Replies
18
Views
2K
Deleted member 103
D
Top