Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim camara As AdvancedCamera
Dim PanelCamara As Panel
Dim Button1 As Button ' captura
dim Button2 As Button ' marcha/paro camara
Dim CamaraOK As Boolean
Dim CamaraVisible As Boolean
' ampliaciones futuras
Dim FlagSoportaZoom As Boolean
Dim FlagSoportaLed As Boolean
Dim FlagSoportaAutoFoco As Boolean
' .................
' .................
' .................
' .................
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
Button1.Enabled = False
' .................
' .................
' .................
' .................
Sub Activity_Resume
Try
camara.Initialize(PanelCamara, "camara")
Catch
CamaraOK = False
Msgbox("Error al iniciar cámara" & CRLF & "Inténtelo de nuevo","")
End Try
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed = True Then
If CamaraOK = True AND CamaraVisible = True Then
camara.StopPreview
camara.Release
End If
DoEvents
Activity.Finish
End If
If CamaraOK = True AND CamaraVisible = True Then
camara.StopPreview
camara.Release
End If
End Sub
Sub Button1_Click
Button1.Enabled = False
camara.TakePicture
End Sub
Sub Button2_Click
' MARCHA/PARO CAMARA
If CamaraOK = True Then
If CamaraVisible = True Then
' parar camara
camara.StopPreview
CamaraVisible = False
Else
' marcha camara
PanelCamara.top=0
Try
camara.StartPreview
CamaraVisible = True
Catch
Log("Error en Camara.StartPreview")
End Try
End If
End If
End Sub
Sub camara_Ready (Success As Boolean)
If Success Then
CamaraOK = True
ConfigurarCamara
Button1.Enabled = True
Else
CamaraOK = False
Msgbox("No se puede poner la cámara en marcha" & CRLF & "Inténtelo de nuevo", "")
End If
End Sub
Sub camara_PictureTaken(Data() As Byte)
Button1.Enabled = True
camara.StartPreview
' ---------------------------------------------------------------------------
' para grabar a memoria
Dim salida As OutputStream
salida = File.OpenOutput(File.DirRootExternal,"foto.jpg",False)
salida.WriteBytes(Data,0,Data.Length)
salida.Close
ToastMessageShow("Imagen guardada en: " & File.Combine(File.DirRootExternal,"foto.jpg"), True)
End Sub
Sub ConfigurarCamara
Dim tmp As String
FlagSoportaZoom = camara.isZoomSupported
If FlagSoportaZoom = False OR camara.MaxZoom = 0 Then
Msgbox("La cámara no soporta zoom","")
End If
tmp = camara.SupportedFlashMode
' [off, auto, on, torch]
Log("flash" & tmp)
If tmp.Contains("torch") Then FlagSoportaLed = True
If FlagSoportaLed = False Then
Msgbox("La cámara no tiene led","")
End If
tmp = camara.SupportedFocusMode
If tmp.Contains("auto") Then FlagSoportaAutoFoco = True
Log("Tipo foco " & tmp)
'[auto, infinity, macro, continuous-picture, continuous-video]
If FlagSoportaAutoFoco = False Then
Msgbox("La cámara no soporta auto-foco","")
Else
'Log("foco" & tmp)
'Camara.FocusMode = ModoFoco
End If
If Activity.Height > Activity.Width Then
' movil vertical
camara.OriPortrait
Else
camara.OriLandscape
End If
DoEvents
If CamaraOK = True AND CamaraVisible = True Then
DoEvents
Try
camara.StartPreview
Catch
Log("Error StartPreview en configurar camara")
End Try
End If
End Sub