Camera just freezes up a

wheretheidivides

Active Member
Licensed User
Longtime User
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

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:

wheretheidivides

Active Member
Licensed User
Longtime User
I commented the line out and was able to click off 4 pictures (size 0) before the camera froze up. The screen froze the picture and the buttons stopped working on the screen. The program crashes. When I rerun the program it gives the error 'camera not ready'. I have to reboot the phone to get the camera to work again.
=======================================
This time it gave an error in cameraclass_takepicture
that is the cameraexclass on the line "cam.TakePicture"

Public Sub TakePicture
cam.TakePicture
End Sub
========================================
I did modify some of the code sense yesterday to see if I could figure out the problem. Here is the new code so it may be helpful in seeing something.

B4X:
'Activity module
Sub Process_Globals

'---------------------------------------------
'Camera
   Private frontCamera As Boolean = False
   
'--------------------------------------------
End Sub

Sub Globals   
'---------------------------------------------
'Camera (Used for camera on pages 5050 & 2000)
   Private camEx As CameraExClass
   
   Dim CamSaveDir, CamSaveFN As String
   
   Dim now As Long
   Dim dt1, dt2, CamCat As String

end sub

Sub Activity_Create(FirstTime As Boolean)
'---------------------------------------------
'Creates folders if it they do not exist
   '-------------------------------------------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved") = False Then
        File.MakeDir (File.DirRootExternal, "/Saved")
   End If
   '-------------------------------------------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK") = False Then
        File.MakeDir (File.DirRootExternal, "/Saved/PDTK")
   End If
   '-------------------------------------------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK/Settings") = False Then
        File.MakeDir (File.DirRootExternal, "/Saved/PDTK/Settings")
   End If
   '-------------------------------------------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK/DataBases") = False Then
        File.MakeDir (File.DirRootExternal, "/Saved/PDTK/DataBases")
   End If
   '-------------------------------------------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK/Pics") = False Then
        File.MakeDir (File.DirRootExternal, "/Saved/PDTK/Pics")
   End If
   
   '-------------------------------------------------------------------------
   'set 4 digit year and create a folder with that year to save pics into
   DateTime.DateFormat = "yyyy"
      dt2 = DateTime.Date(DateTime.now)
   '-------------------------------------------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK/Pics/" & dt2) = False Then
        File.MakeDir (File.DirRootExternal, "/Saved/PDTK/Pics/" & dt2)
   End If

Sub Button2015PicExp_Click
'-----------------------------------------------
'Assign Category to save in pics folder as
   CamCat = "Exp"

'------------------------------------------------
'Camera take picture
   camEx.TakePicture

'--------------------------------------------------

End Sub

Sub Button2017PicInc_Click
'-----------------------------------------------
'Assign Category to save in pics folder as
   CamCat = "Inc"

'------------------------------------------------
'Camera take picture
   camEx.TakePicture

'--------------------------------------------------

End Sub

Sub Button2016PicPayStub_Click
'-----------------------------------------------
'Assign Category to save in pics folder as
   CamCat = "Stub"

'------------------------------------------------
'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
'--------------------------------------------
'dt2 is current year folder
   dir = File.DirRootExternal & "/Saved/PDTK/Pics/" & dt2 

'CamCat is category (income, expense or paystub), dt1 is curent date and time
   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
 
Last edited:
Upvote 0
Top