Android Question take picture from front camera

Devv

Active Member
Licensed User
how can i use the front camera ?


this code is working for the back camera

B4X:
Sub Globals
    Dim camera1 As Camera
    Dim Panel1 As Panel
    Dim timer_cam As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    camera1.Initialize(Panel1, "Camera1")
End Sub
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camera1.StartPreview
        timer_cam.Initialize("timer_cam",1000)
        timer_cam.Enabled = True
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

Sub timer_cam_tick
    camera1.TakePicture
    timer_cam.Enabled = False
End Sub


Sub Camera1_PictureTaken (Data() As Byte)
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
    ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "1.jpg"), True)
End Sub
 
Last edited:

Devv

Active Member
Licensed User
NJDude

thanks for replay, i had seen the class but i don't need it features

in the documentation Erel said the we could use the front camera by only using the camera lib

Initialize2 (Panel As android.view.ViewGroup, EventName As String, CameraId As Int)
Same as Initialize. CameraId is the id of the hardware camera.
This method is only available from Android 2.3+.
what is the front and back camera id ? does it vary from device to another ?
 
Top