using Camera Flash without preview (CameraEx Class)

jesustarre

Member
Licensed User
Longtime User
Hello,

How can I activate the camera flash (torch mode) with out camera preview?

I'm using CameraEx class and the only way to activate the flash was with the camex.startpreview

Thanks in advance
 

Paulsche

Well-Known Member
Licensed User
Longtime User
i have the same problem.

I use the light switch in a scroll view, and when the light shines,
the ScrollView jerky.
Camera panel is invisible

Does anyone have a solution?

I found solution:
as soon camera light is on,
just run "camex.stoppreview".
 
Last edited:
Upvote 0

RichyK68

Active Member
Licensed User
Longtime User
I don't know if I should start a new thread but I find using the CameraEx class or even the ACL library that once the camera class has been initialized in my app no other app can use the camera (unless I remove my app from Android's tasklist history). I simply want to be able to turn the flashlight on and off, I don't need any camera functionality, I've tried StopPreview, but it makes no difference. Once the flashlight is turned off, I'd still like any other app to be able to use the camera or flashlight.
 
Upvote 0

Andrey Lopatin

New Member
Licensed User
Longtime User
With the Camera library you will need to call StartPreview. You can pass a hidden panel to it.
Hi, Erel.
What did you exactly mean saying "hidden panel"?
1. When I set Visible = False to Panel, I get the following error when compile: "java.lang.NoSuchMethodException: setFlashMode [class java.lang.String]".
2. When I set panel size to 1x1 px and hide it behind another panel, then phone becomes hot after 10 minutes because of CPU usage for resizing camera view.
How can I avoid these issues?
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
see the example below. This starts cameraEx Class in Torchmode without showing a preview. The Panel1 with the camera preview lies behind Panel2 which is visible....
B4X:
Sub Process_Globals
    Private frontCamera As Boolean = False
End Sub

Sub Globals
    Private Panel1 As Panel
    Private camEx As CameraExClass
    Dim Panel2 As Panel


End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("1")
    Panel1.Initialize("")
    Panel2.Initialize("")
    Activity.AddView(Panel1,0,0,100%x,100%y)
    Activity.AddView(Panel2,0,0,100%x,100%y)
    Panel2.Color = Colors.Red

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.SetJpegQuality(90)
        Log(camEx.GetSupportedFlashModes) 'here check first which modes are supported
        camEx.SetFlashMode("torch") 'will turn it on into torch mode
        camEx.CommitParameters
        camEx.StartPreview   
        Log(camEx.GetPreviewSize)
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…