personalapps
Member
I am using media chooser to capture image and after reducing the size, I am sending it to Gemini API. Is it possible to capture the lowest possible resolution when using the camera and then send that to the Gemini API ?
Current Code:
Current Code:
current code captures image and then reduces size:
Private Sub Capture_Click
Wait For (chooser.CaptureImage) Complete (Result As MediaChooserResult)
Log($"The media directory is ${Result.MediaDir} and the file name is ${Result.MediaFile} and the mime is ${Result.Mime} ."$)
B4XLoadingIndicator1.Show
ShowMedia(Result)
ConvertImageToBase64ResizeImage(Result.MediaFile,Result.MediaDir)
End Sub
Sub ConvertImageToBase64ResizeImage(filename As String, dir As String) As String
Dim su As StringUtils
Dim in As InputStream
Dim bmp As Bitmap
Dim resizedBmp As Bitmap
Dim out As OutputStream
Dim data() As Byte
Dim base64 As String
' Load the original image
bmp.Initialize(dir,filename)
' Resize the image to a smaller size
resizedBmp = bmp.Resize(300, 300, True)
Log($"Image resized to:Width: ${resizedBmp.Width} Heigth: ${resizedBmp.Height}"$)
' Save the resized image to a byte array
out.InitializeToBytesArray(0)
resizedBmp.WriteToStream(out, 100, "JPEG") ' Adjust quality as needed (100 = max quality)
out.Close
' Convert byte array to Base64
data = out.ToBytesArray
base64 = su.EncodeBase64(data)
SendImageToGemini(base64)
Return base64
End Sub