Android Question How to draw on a canvas in Android

saeed10051

Active Member
Licensed User
Hi all
i have seen on code from Erel where following code is executed on B4J side to draw on a canvas

Sub cvs_MouseDragged (EventData As MouseEvent)
cvs.DrawCircle(EventData.X, EventData.Y, 30dip, fx.Colors.From32Bit(Rnd(0xFF000000, -1)), True, 0)
End Sub

Here as we see that MouseDragged sub is using MouseEvent to draw. However if i want to use the same sub in B4A, i am unable to find an event which i can use to draw. I am trying to create an app in which on dragging my finger on the screen i can draw on the screen.
 

aeric

Expert
Licensed User
In B4X XUI, a Canvas must be linked to a Panel (B4A, B4i) or a Pane (B4J) with the B4XCanvas1.Initialize method.
You may need to call B4XCanvas1.Invalidate to make the drawing active.
This is different from B4A and B4i where you need to Invalidate the Panel.
You may have a look at the B4X Graphics and B4X XUI booklets.
 
Upvote 0

saeed10051

Active Member
Licensed User
Hi Aeric
thanks for the reply
however i am missing one point here, the examples given here refer to drawing something grammatically and displaying it on the canvas. I want to draw by dragging my finger on the screen. how to capture that event. When i see the code by Erel in B4J (as given in my original question) he has used the mouse drag to draw something, how to capture that event while working with B4A , as here we do not have a mouse we just drag our finger on the screen.
 
Upvote 0

saeed10051

Active Member
Licensed User
Hi Angel
i have reviewed the code, however i am unable to catch that in which event are you writing the code to draw the lines. There is a Sub ASDraw1_Touch (Action As Int, XY As Map)
but within the sub all the code is commented.
can you please explain.
 
Upvote 0
Top