Android Question Photo with Advanced Camera Picture Library ftp to send out looks bad.

TheArkhangel

Member
Licensed User
Longtime User
Greetings to all
I followed the tutorial of the Advanced Camera bookstore and I am sending the picture I get FTP to a computer ..... my problem is that the picture always looks bad ..... to send while the device is perfectly.

Somebody can help me ?

Thanks


B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Photo Clinica
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: landscape
#End Region

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim ftp1 As FTP
End Sub

Sub Globals
   
    Dim camera1 As AdvancedCamera
    Dim btnTakePicture As Button
    Private btnFlash As Button
    Dim Panel1 As Panel
    Dim paciente As String
    Dim nfichero As String
    Dim fecha As String
    Dim dia As Int
    Dim mes As Int
    Dim año As Int
    Dim hora As Int
    Dim minutos As Int
    Dim segundos As Int
       
    Private txtbPaciente As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    ftp1.Initialize("ftp1","192.168.1.71",21,"user","pass")
End Sub
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camera1.StartPreview
        btnTakePicture.Enabled = True
    Else
        ToastMessageShow("Imposible activar CAMARA", True)
    End If
End Sub

Sub Activity_Resume
    btnTakePicture.Enabled = False
    camera1.Initialize(Panel1, "Camera1")
   
End Sub

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

Sub Camera1_PictureTaken (Data() As Byte)
    dia=DateTime.GetDayOfMonth (DateTime.Now)
    mes=DateTime.GetMonth(DateTime.Now)
    año=DateTime.GetYear(DateTime.now)
    hora=DateTime.GetHour(DateTime.now)
    minutos=DateTime.GetMinute(DateTime.now)
    segundos=DateTime.GetSecond(DateTime.now)
    fecha=dia & mes & año & "_" & hora & minutos & segundos
    camera1.StartPreview
    Dim out As OutputStream
    nfichero="P" & fecha & ".jpg"
    paciente="P" & txtbPaciente.text
    out = File.OpenOutput(File.DirRootExternal, nfichero, False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
    ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, nfichero), True)
    btnTakePicture.Enabled = True
    ftp1.UploadFile(File.DirRootExternal,nfichero,True,"/Users/Domingo/Documents/Pacientes/" & nfichero)
    
End Sub

Sub ftp1_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim s As String
    s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

Sub ftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
End Sub

Sub btnTakePicture_Click
    If txtbPaciente.Text="0" Then
        ToastMessageShow("Debe introducir un numero de Paciente", True)
    Else
        btnTakePicture.Enabled = False
    'camera1.FocusMode="AUTO"
    camera1.PictureSize(800,600)
    camera1.TakePicture
    End If
   
End Sub

Sub btnFlash_Click
    Dim fl As String
    fl=camera1.CurrentFlashMode
    If fl= "off" Then
        camera1.FlashOn
        ToastMessageShow("Flash ON", True)
    Else
        camera1.FlashOff
        ToastMessageShow("Flash OFF", True)
    End If   
End Sub

Sub Panel1_Click
        camera1.FocusMode="AUTO"
End Sub

Sub txtbPaciente_TextChanged (Old As String, New As String)
    paciente=txtbPaciente.Text
End Sub


P2072016_105057.jpg
P2072016_105311.jpg
 

TheArkhangel

Member
Licensed User
Longtime User
Yes, the Uploadcomplete are Success...

Please can you gime the CameraEx link and how to initilice only firsttime ?

tnaks Erel
 
Upvote 0

TheArkhangel

Member
Licensed User
Longtime User
I'm use the example of camEx and adapt ftp upload and I have the same problem the send picture are wrog and I can't use autofocus to take view a picture good
any help ? when i upload the picture to a ftp server online (not server at my lan) when i download the picture the file are corrupted.... ?

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: False
    #ApplicationLabel: Camera example
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    Private frontCamera As Boolean = False
    Dim ftp1 As FTP
End Sub

Sub Globals
    Private Panel1 As Panel
    Private camEx As CameraExClass
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume
    InitializeCamera
End Sub

Private Sub InitializeCamera
    camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
    frontCamera = camEx.Front
End Sub

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

Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.SetJpegQuality(90)
        camEx.StartPreview
        camEx.SetPictureSize(800,600)
       
        Log(camEx.GetPreviewSize)
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

Sub btnTakePicture_Click
    ftp1.Initialize("ftp1","192.168.1.71",21,"user","user")
    camEx.TakePicture
End Sub

Sub btnFocus_Click
    ftp1.Initialize("ftp1","192.168.1.71",21,"user","user")
    'camEx.FocusAndTakePicture
    Log(camEx.GetSupportedFocusModes)
    camEx.SetFocusMode("contunuous-picture")
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirRootExternal
    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)
    ftp1.UploadFile(dir,filename,True,"/Users/Domingo/Documents/Pacientes/" & filename)
End Sub

Sub ftp1_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim s As String
    s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

Sub ftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
End Sub


Sub ChangeCamera_Click
    camEx.Release
    frontCamera = Not(frontCamera)
    InitializeCamera
End Sub

Sub btnEffect_Click
    Dim effects As List = camEx.GetSupportedColorEffects
    If effects.IsInitialized = False Then
        ToastMessageShow("Effects not supported.", False)
        Return
    End If
    Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
    camEx.SetColorEffect(effect)
    ToastMessageShow(effect, False)
    camEx.CommitParameters
End Sub

Sub btnFlash_Click
    Dim f() As Float = camEx.GetFocusDistances
    Log(f(0) & ", " & f(1) & ", " & f(2))
    Dim flashModes As List = camEx.GetSupportedFlashModes
    If flashModes.IsInitialized = False Then
        ToastMessageShow("Flash not supported.", False)
        Return
    End If
    Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
    camEx.SetFlashMode(flash)
    ToastMessageShow(flash, False)
    camEx.CommitParameters   
End Sub
Sub btnPictureSize_Click
    Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
    Dim current As CameraSize = camEx.GetPictureSize
    For i = 0 To pictureSizes.Length - 1
        If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
    Next
    Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
    camEx.SetPictureSize(ps.Width, ps.Height)
    ToastMessageShow(ps.Width & "x" & ps.Height, False)
    camEx.CommitParameters       
End Sub
 
Upvote 0

Similar Threads

Top