Android Question how i can draw with Panel1_OnTouch after using camera

sufyan

Member
Licensed User
Longtime User
hi everyone
I would like to get help , I m now working with application that allow the user to take picture using
CameraExClass lib then he/she can draw on the picture using panal on touch .
the picture is taking but the on touch is not working with me . please check my code

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private frontCamera As Boolean = False
     Dim fromx,fromy,tox,toy As Int
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private Panel1 As Panel
     Private Panel2 As Panel
    Private camEx As CameraExClass
    'these veriable for the menu animation
    Private Label1 As Label
    Private Label2 As Label
    Private EditText1 As EditText
    Private Button6 As Button
    Private Button7 As Button
   
    Private Button13 As Button
    Private Label3 As Label
    Private Label4 As Label
    Private Label5 As Label
    Private Label6 As Label
    Private Label7 As Label
    Private Button1 As Button
    Private Button10 As Button
    Private Button11 As Button
    Private Button12 As Button
    Private Button2 As Button
    Private Button3 As Button
    Private Button4 As Button
    Private Button5 As Button
    Private Button9 As Button
    Public c_mode As Int =0 ' to use it on application to identified the mode c_mode = 0 camera on , c_mode =1 camera off
    Public filename As String ' to save the name of the picture
    Private Button15 As Button
    'verible for the draw event
    Dim Obj1 As Reflector
    Dim picCanvas As Canvas
    Dim DestRect As Rect
   
   

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    'creat folder for the pictures
    If FirstTime Then
        'test for folder and create if not present ..
        Dim MyPath As String
        MyPath = File.DirDefaultExternal & "/MyEcamera"
        If File.Exists(MyPath, "") = False Then
            File.MakeDir(File.DirDefaultExternal, "MyEcamera")
        End If
        If File.Exists(MyPath, "") = False Then
            File.MakeDir(File.DirInternal , "MyEcamera")
        End If
    End  If
    'put the date and time on label 1
    DateTime.DateFormat="dd-MM-yy HH:mm"
    Dim MyDate As String=DateTime.Date(DateTime.Now)
    Label1.Text=MyDate
   
    'Panel2.SendToBack
    picCanvas.Initialize(Panel1)
    DestRect.Initialize(0dip, 0dip, 100%x, 100%y)
    picCanvas.DrawRect(DestRect,  Colors.Transparent, True, 1dip)
    Panel1.Invalidate
    ' sets the Touch event for Panel1 using the Reflection library
    Obj1.Target = Panel2
    Obj1.SetOnTouchListener("Panel2_OnTouch")
   
End Sub

Sub Activity_Resume
    InitializeCamera
  End Sub
Private Sub InitializeCamera
    camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
    frontCamera = camEx.Front
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    camEx.Release
End Sub
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.JpegQuality=100
        'camEx.SetPreviewSize(480,320)
        camEx.SetContinuousAutoFocus
        camEx.CommitParameters
        camEx.StartPreview
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
   
    Dim dir As String = File.DirDefaultExternal & "/MyEcamera"
    camEx.SavePictureToFile(Data, dir, filename)
    camEx.StartPreview 'restart preview
    'send a broadcast intent to the media scanner to force it to scan the saved file.
    Dim Phone As Phone
    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_MOUNTED","file://" & File.Combine(dir, filename))
    Phone.SendBroadcastIntent(i)
    ToastMessageShow("Picture saved." , True)
    'load the image to the panel
    camEx.StopPreview
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(dir , filename))
    bd.Gravity = Gravity.FILL
    Panel1.Background =bd
    ' drwa event
   

   
End Sub
Sub Button7_Click ' change with diferent mode
    camEx.TakePicture 
End Sub

'============================================================================================
Sub Panel1_OnTouch(viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean

  Select action
    Case Panel1.ACTION_DOWN
    'puts a circle if the user just touches the screen briefly
     fromx = X
     fromy = Y
     picCanvas.DrawCircle(fromx, fromy, 10dip, Colors.Red, True, .1dip)
    Case Panel2.ACTION_UP
        'puts final circle as the user lifts their finger off the screen
        tox = X
        toy = Y
        picCanvas.DrawCircle(tox, toy, 10dip, Colors.Red, True, .1dip)
    Case Panel1.ACTION_MOVE
        'Filled circles stop jaggies between lines
        tox = X
        toy = Y
        picCanvas.DrawCircle(fromx, fromy, 10dip, Colors.Red, True, .1dip)
        picCanvas.DrawLine(fromx,fromy,tox,toy,Colors.Red,20dip)
        picCanvas.DrawCircle(tox, toy, 10dip, Colors.Red, True, .1dip)
        fromx = tox
        fromy = toy
    End Select
    Panel1.Invalidate   
    Return True
End Sub
 

sufyan

Member
Licensed User
Longtime User
Erel
thank you for your quick respond
I change the panel 2 to panel1 and I have the same problem

Obj1.Target = Panel1
Obj1.SetOnTouchListener("Panel1_OnTouch")
 
Upvote 0
Top