Android Question Camera Problems

Bladimir Silva Toro

Active Member
Licensed User
Longtime User
Hi

I have 2 problems with the use of the smartphone camera

1st: The camera preview the side image and not the right as it should be, see the following photo:

1-1.jpg


The right thing would be to show it like this:
1-2.jpg


The code in B4A is:

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

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 camera1 As Camera
    Private PanelFoto As Panel
    Private BtnTomarFoto As Button
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("FrmTomarFoto")

End Sub

Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camera1.StartPreview
        BtnTomarFoto.Enabled = True
    Else
        Msgbox("No Se puede Abrir la Camara","Advertencia")
    End If
End Sub

Sub Activity_Resume
    BtnTomarFoto.Enabled = False
    camera1.Initialize(PanelFoto, "Camera1")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    camera1.Release
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
    camera1.StartPreview
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "Download/1.jpg", False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
    Msgbox("Imagen Almacenada Correctamente.","Felicitaciones!!!")
    FrmAddServicio.Foto_Tomada=1
    Activity.Finish
End Sub


Sub BtnTomarFoto_Click
    BtnTomarFoto.Enabled = False
    camera1.TakePicture
End Sub

2nd: The application in B4A does not have the permission for the camera, when it is enabled it works correctly, see photo:

1-3.jpg


My version of B4A is 9.5 and the camera library is 2.20

The code in B4A is:

B4X:
rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
    Msgbox("No Autoriza Permiso Para Uso Camara.","Advertencia!!!")
    Msgbox("Aplicación NO Puede Ser Ejecutada","Advertencia!!!")
    ExitApplication
End If

I appreciate all your help.
 
Top