Android Question [solved] Photo image file size


Licensed User
Hi all,
please refresh my surely outdated knowledge about the subject.
I'd like to let a B4A/B4i app takes up a photo (using whatever resolution the device is set to), reduce its resulting file size to a minimum (keeping the best quality possible) and finally upload it to a server of mine.
On a later time, that file should be downloaded an photo/image showed to the user.

Nothing special, but I'm concerned about the giant steps made about the cameras 'features on newer smartphones/tablets. So I expect a modern photo to be very large (referring to file size rather than image size). This will impact upload/download time and data traffic consumed.

I'm envisioning two competing strategies (they could be even combined): operating on the original image as soon as it's taken and zipping the file to upload.

Any hint? Did I miss something important? How did you cope with this subject in your apps?

ps: I somewhat recall a "shared your creation" by Ilan..let me search for it; eventually I'll be lucky and find a good solution there.


Alexander Stolte

Licensed User
How did you cope with this subject in your apps?
My answer is simple:
1. convert the image to bytes with this code
2. convert the bytes to image
Public Sub SavePictureToFile(Data() As Byte, Dir As String, FileName As String)
    Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
    out.WriteBytes(Data, 0, Data.Length)
End Sub
3. upload the bitmap to the server

You can play with the quality, save the image on your phone and look how the quality is, the file size is good for the quality and file size.
I use this code in my apps ~200kb per image.


Licensed User
I use this code in my apps ~200kb per image
Thank you Alexander.
So, considering 200KB images, what remains to be evaluated is whether to add the zipping step to reduce traffic data and upload/download time. I guess that some experimenting on the field will answer the question :)


Licensed User
Oh, another point: to take a photo, would you still use the Camera Intent or switch to CameraEx (or Camera2 depending on Android version)?
I used the former in an old project of mine and I'm aware that I've to update it in order to use FileProvider, but eventually interacting directly with the camera is nowadays the preferred method?
BTW, I will have to search on how to take photos on iOS too (but let's have a functioning Android app first).

To better focus on my specific goal: I expect pictures taken out of paper documents being A5, A4 or even larger in size. That means good resolution but non so many colors (i hope..ehehe).

ps: should this second point appear in a different thread? It's still about keeping the resulting file size at a minimum when taking good resolutions photos, but focuses on the preferred way to take a photo today.. hmm, re-reading it I'm now inclined to open a different thread..