How to draw on screen with finger?

ozgureffe

Member
Licensed User
Longtime User
Hi,
I am looking for a solution to draw something on a panel? I found some samples in multitouch Using Agraham's Gestures library here -> Actually that sample is very similar to what i am looking for but is complicated for me as i am a beginner and my point is not related with multi touch... I am not related with multi touching functions...

Is there any simple way for this without using multi gesture? Single touch is enough for me for this project ?

And is it possible to save my drawings as image files ?

Thank You..
 
Last edited:

Kamac

Active Member
Licensed User
Longtime User
without using multi gesture?

Means you don't want multi-touch?

Only multi gesture library allows you to use multi-touch with b4a.


And is it possible to save my drawings as image files?


Here's how you save ImageView as .png

Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "Test.png", False)
Bitmap1.WriteToStream(out, 100, "PNG")
Out.Close

Instead of Bitmap1 you have to give your ImageView name.



Edit@

Here's some very basic drawing:

B4X:
Sub Globals
    Dim Canvas1 As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Canvas1.Initialize(Activity) 'Initialize the canvas (drawer) and makes it draw on the activity (form).
End Sub

Sub Activity_Touch(Action As Int, tx As Float, ty As Float)
    Canvas1.DrawCircle(tx, ty, 5dip, Colors.Red, False, 2dip)
    Activity.Invalidate3(tx - 7dip, ty - 7dip, tx + 7dip, ty + 7dip)
End Sub

i hope it'll work, didn't test it.

Edit2@

Repaired and tested. It works.
 
Last edited:
Upvote 0

ozgureffe

Member
Licensed User
Longtime User
Yes! I mean I don't want and I don't need multi-touch...
I am looking something simpler with only basic logic about drawing.

And is it possible to save my drawing as an image file?
 
Upvote 0

ozgureffe

Member
Licensed User
Longtime User
Thak you so much
I am just tested your code it is working if draw in slow speed but if i move my finger faster it becomes dotty :)
 
Upvote 0

ozgureffe

Member
Licensed User
Longtime User
Thank you so much Kamac everything is working flawless now.
Only problem which is left is dots without connection if i draw a little bit faster.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
I assume you are doing several circles to fill it. If so, instead of
B4X:
Sub Activity_Touch(Action As Int, tx As Float, ty As Float)
    Canvas1.DrawCircle(tx, ty, 5dip, Colors.Red, False, 2dip)
   Canvas1.DrawCircle(tx, ty, 4dip, Colors.Red, False, 2dip)
   Canvas1.DrawCircle(tx, ty, 3dip, Colors.Red, False, 2dip)
   Canvas1.DrawCircle(tx, ty, 2dip, Colors.Red, False, 2dip)
   Canvas1.DrawCircle(tx, ty, 1dip, Colors.Red, False, 2dip)
   Activity.Invalidate3(tx - 7dip, ty - 7dip, tx + 7dip, ty + 7dip)
End Sub
Why not
B4X:
Sub Activity_Touch(Action As Int, tx As Float, ty As Float)
    Canvas1.DrawCircle(tx, ty, 5dip, Colors.Red, True, 2dip)
   Activity.Invalidate3(tx - 7dip, ty - 7dip, tx + 7dip, ty + 7dip)
End Sub
As the flag after the colour is for filled or not filled.
 
Upvote 0
Top