Spanish Como Optimizar Imagenes UploadFile

ebqlabs

Active Member
Licensed User
Hola,

Necesito optimizar mis imagenes cuando saco una foto y la subo al FTP.

Realizo:

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "foto.jpg"
    Dim dir As String = File.DirRootExternal
    now = DateTime.Now
  
    camEx.SavePictureToFile(Data, dir, filename)
    camEx.StartPreview 'vista previa de reinicio

    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)
  
FTP.UploadFile(File.DirRootExternal, "foto.jpg", False, "public_html/sal/archivos/fotos/"imagen.jpg")
  
End Sub


Sub FTP_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 FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success = True Then
   
Msgbox("GRABADO CON EXITO", ser_log_usr.MensajeGlobal)
   
    Else
 
      Msgbox("Error de conexion", ser_log_usr.MensajeGlobal)
    End If
End Sub

Por ahora me lo sube con 509 KB

Pregunta, ¿se podrá bajar el tamaño de ella ?

Saludos.
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Prueba reduciendo el tamaño de la imagen y/o reduciendo la "calidad" de la imagen.

B4X:
    '
    ' Se abre el archivo que contiene la imagen
    Log("Se habre el archivo: " & FileNamePre)
    lcImage.Initialize3 (AutoRotate_Image(DirName, FileNamePre))
    lcDataLog    = $"New Image (${FileNamePre}) Height: ${lcImage.Height}  Width: ${lcImage.Width} "$
    Log(lcDataLog)
    '
    If lcImage.Height > lcImage.Width Then
        lcImageRes.Initialize3( ResizeImage(lcImage, 600, 800) )
        lcDataLog    = $"New Image (${FileName}) Height: ${lcImageRes.Height}  Width: ${lcImageRes.Width} "$
        Log(lcDataLog)
    Else
        lcImageRes.Initialize3( ResizeImage(lcImage, 800, 600) )
        lcDataLog    = $"New Image (${FileName}) Height: ${lcImageRes.Height}  Width: ${lcImageRes.Width} "$
        Log(lcDataLog)
    End If
    '
    ' Se guarda la imagen al 80% de la Calidad
    lcNewImage    = File.OpenOutput(DirName, FileName, False)
    lcImageRes.WriteToStream(lcNewImage,90,"JPEG")
    lcNewImage.Close

Espero te sirva.

Saludos,

Edgar
 
Top