I'm trying to get the camera to work. It constantly freezes up. I have to turn phone off to get it to reboot. It may be an issue with how I'm saving the files to disk. I am using CameraExclass. I think it's how i'm saving to disk as it crashes at that point.
dt1 is the date and time while dt2 is just the 4 digit year. I am trying to save the picture into /Saved/PDTK/Pics/ under today's year (which is dt2) so /Saved/PDTK/Pics/2013.
The filename is a category first (income, expsenses or pay stub), the date and time with .jpg at the end.
Thanks in advance.
Here is some code. This is suspect
dir = File.DirRootExternal & "/Saved/PDTK/Pics/" & dt2
filename = CamCat & dt1 & ".jpg"
camEx.SavePictureToFile(Data, dir, filename
or maybe it's something else. A lot of times the first picture is taken OK but the 2nd picture frezzes the camera. Is there a length of time before you wan take another pic?
dt1 is the date and time while dt2 is just the 4 digit year. I am trying to save the picture into /Saved/PDTK/Pics/ under today's year (which is dt2) so /Saved/PDTK/Pics/2013.
The filename is a category first (income, expsenses or pay stub), the date and time with .jpg at the end.
Thanks in advance.
Here is some code. This is suspect
dir = File.DirRootExternal & "/Saved/PDTK/Pics/" & dt2
filename = CamCat & dt1 & ".jpg"
camEx.SavePictureToFile(Data, dir, filename
B4X:
'---------------------------------------------
'Creates folders if it does not exist
File.MakeDir(File.DirRootExternal,"/Saved")
File.MakeDir(File.DirRootExternal,"/Saved/PDTK")
File.MakeDir(File.DirRootExternal,"/Saved/PDTK/Settings")
File.MakeDir(File.DirRootExternal,"/Saved/PDTK/DataBases")
File.MakeDir(File.DirRootExternal,"/Saved/PDTK/Pics")
DateTime.DateFormat = "yyyy"
dt2 = DateTime.Date(DateTime.now)
File.MakeDir(File.DirRootExternal,"/Saved/PDTK/Pics/" & dt2)
'---------------------------------------------
Sub Button2015PicExp_Click
'-----------------------------------------------
'Assign Category to save in pics folder as
CamCat = "Expense_"
'------------------------------------------------
'Camera take picture
camEx.TakePicture
'--------------------------------------------------
End Sub
Sub Button2017PicInc_Click
'-----------------------------------------------
'Assign Category to save in pics folder as
CamCat = "Income_"
'------------------------------------------------
'Camera take picture
camEx.TakePicture
'--------------------------------------------------
End Sub
Sub Button2016PicPayStub_Click
'-----------------------------------------------
'Assign Category to save in pics folder as
CamCat = "PayStub_"
'------------------------------------------------
'Camera take picture
camEx.TakePicture
'--------------------------------------------------
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
'--------------------------------------------------
'Get date and time year-month-day_hour-min-sec
DateTime.DateFormat = "yyyy-MM-dd_HH-mm-ss"
dt1 = DateTime.Date(DateTime.now)
'--------------------------------------------
Dim dir As String
Dim filename As String
dir = File.DirRootExternal & "/Saved/PDTK/Pics/" & dt2
filename = CamCat & dt1 & ".jpg"
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.SetContinuousAutoFocus
camEx.SetJpegQuality(90)
camEx.CommitParameters
camEx.StartPreview
Else
ToastMessageShow("Camera not ready. Turn phone off and on again to use camera.", True)
End If
'--------------------------------------------------
End Sub
Private Sub InitializeCamera
'--------------------------------------------------
camEx.Initialize(Panel2020, frontCamera, Me, "Camera1")
frontCamera = camEx.Front
'--------------------------------------------------
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'
'---------------------------------------------
'Releases camera so other applications can use it
camEx.Release
'-----------------------------------------------
End Sub
Sub Activity_Resume
'-----------------------------------------------
'init camera
InitializeCamera 'SR
'-----------------------------------------------
End Sub
or maybe it's something else. A lot of times the first picture is taken OK but the 2nd picture frezzes the camera. Is there a length of time before you wan take another pic?
Last edited: