Hi
I am beginner with Basic4Android but i want to progress. I work on application torch and more options.
But i have error when I press my button flash. This is my project.
Thank
I am beginner with Basic4Android but i want to progress. I work on application torch and more options.
But i have error when I press my button flash. This is my project.
B4X:
#Region Project Attributes
#ApplicationLabel: Application LED
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: false
#End Region
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
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.
Dim btntorche As Button
Private Panel1 As Panel
Private camEx As CameraExClass
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("accueil")
'Msgbox("Bienvenu dans l'application Led", "")
End Sub
Sub Activity_Resume
InitializeCamera
End Sub
Sub Activity_Pause (UserClosed As Boolean)
camEx.Release
End Sub
Sub btntorche_click
Log("btntorche")
Dim F() As Float = camEx.GetFocusDistances
Log(F(0) & ", " & F(1) & ", " & F(2))
Dim flashModes As List = camEx.GetSupportedFlashModes
If flashModes.IsInitialized = False Then
ToastMessageShow("Flash non supporté.", False)
Return
End If
Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
camEx.SetFlashMode(flash)
ToastMessageShow(flash, False)
camEx.CommitParameters
End Sub
Private Sub InitializeCamera
camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
frontCamera = camEx.Front
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
Dim filename As String = "1.jpg"
Dim dir As String = File.DirRootExternal
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_SCANNER_SCAN_FILE", _
"file://" & File.Combine(dir, filename))
Phone.SendBroadcastIntent(i)
ToastMessageShow("Picture saved." & CRLF & "File size: " & File.Size(dir, filename), True)
End Sub
Sub Camera1_Ready (Success As Boolean)
If Success Then
camEx.SetJpegQuality(90)
camEx.CommitParameters
camEx.StartPreview
Log(camEx.GetPreviewSize)
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub
Thank