Android Question Camera2: Auto_flash in Preview

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't think that the flash is supposed to be turned on while in preview.

This code forces it to be on in preview mode (tested on a single device):
B4X:
cam.AutoExposureMode = "OFF"
cam.PreviewSettingsMap.Put("FLASH_MODE", 2) 'TORCH
cam.StartPreview(MyTaskIndex, VideoMode)
cam.AutoExposureMode = "ON"
cam.PreviewSettingsMap.Put("FLASH_MODE", 2) 'TORCH
cam.StartPreview(MyTaskIndex, VideoMode)
 
Upvote 0

Karl Matzinger

Member
Licensed User
Hi Erel,
Preview torch works great, but when taking a picture in darkness the ON_AUTO_FLASH isn't working - no flash and the taken picture is dark.
sorry for delay ...

I added 2 buttons

B4X:
Sub btnLightOff_Click
   cam.AutoExposureMode = "OFF"
   cam.PreviewSettingsMap.Put("FLASH_MODE", 2) 'TORCH
   cam.StartPreview(MyTaskIndex, VideoMode)
End Sub

Sub btnLightOn_Click
   cam.AutoExposureMode = "ON"
   cam.PreviewSettingsMap.Put("FLASH_MODE", 2) 'TORCH
   cam.StartPreview(MyTaskIndex, VideoMode)
End Sub
Or did I wrong?

tx
karl
 
Last edited:
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
for off light set '0' on FLASH_MODE

B4X:
private Sub FlashEstado(LightOn As Boolean) As ResumableSub

    Try
       

        Estado = B4XFlash.Value
        cam.AutoExposureMode = IIf(LightOn, "ON","OFF")
        cam.PreviewSettingsMap.Put("FLASH_MODE", IIf(LightOn,2,0)) 'TORCH

           
        cam.StartPreview(MyTaskIndex, VideoMode)
        cam.AutoExposureMode =  IIf(LightOn, "ON","OFF")
        cam.PreviewSettingsMap.Put("FLASH_MODE", IIf(LightOn,2,0)) 'TORCH
   
   
   
        cam.StartPreview(MyTaskIndex, VideoMode)
       
        Return True
    Catch
        Log(LastException)
        Return False
    End Try

End Sub


End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…