I want to take a picture when the PanelCamera is visible. But I can not initialize camera. When I press on the BtnCamera, program crashes. How can I sole this problem? My codes are given below;
B4X:
Sub BtnCamera_Click
PanelMain.Visible = False
PanelCamera.Visible = True
btnTakePicture.Enabled = False
camera.Initialize(PanelCamera, "Camera")
End Sub
Sub Camera_Ready (Success As Boolean)
If Success Then
camera.StartPreview
btnTakePicture.Enabled = True
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub
Sub Camera_PictureTaken (Data() As Byte)
camera.StartPreview
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal, "picture.jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("Image saved: " & File.Combine(File.DirInternal, "picture.jpg"), True)
PhotoUpload
btnTakePicture.Enabled = True
End Sub
Sub btnTakePicture_Click
btnTakePicture.Enabled = False
camera.TakePicture
End Sub