Android Question Saving quality in Camera2

josejad

Expert
Licensed User
Longtime User
Hi:

I'm using CamEx2 to make pictures in my app.
I was using the sample code with almost no modifications, so everybody was using the same camera resolution.
But when I get the pics of the users, some of them have good quality (about 300 kb, enough...), but with others I get poor quality (about 50-100 kb per pic).
So I've set a button to set the quality and save it.

If I test in my phone, it's ok, with low resolutions I get 50-100kb images, with higher I get 2-4Mb pics.
But in the phone of some users, the images quality is the same.

The code is:
B4X:
Sub btnResolution_Click
    Dim resolution As List = cam.GetSupportedCaptureSizes
    Dim i As Int = resolution.IndexOf(cam.CaptureSize)
    i = (i + 1) Mod resolution.Size
    cam.CaptureSize = resolution.Get(i)
    'save the selected size:
    File.WriteMap(Starter.Path, "resolucion.txt", CreateMap("width": cam.CaptureSize.Width, "height": cam.CaptureSize.Height))
    btnResolution.Text = resolution.Get(i)
    cam.StartPreview(MyTaskIndex, VideoMode)
End Sub


In Activity_Create
B4X:
.
.
.
cam.Initialize(pnlCamera)
    If File.Exists(Starter.Path, "resolucion.txt") Then
        Dim m As Map = File.ReadMap(Starter.Path, "resolucion.txt")
        Log(m)
        Dim w As Int = m.Get("width")
        Dim h As Int = m.Get("height")
        cam.CaptureSize.Initialize(w, h)
        btnResolution.Text = m.Get("width") &"x"& m.Get("height")
    End If

Thanks in advance
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't think so. I don't understand the logic behind this code:
B4X:
 Dim resolution As List = cam.GetSupportedCaptureSizes
    Dim i As Int = resolution.IndexOf(cam.CaptureSize)
    i = (i + 1) Mod resolution.Size
    cam.CaptureSize = resolution.Get(i)

I think that you took it from the example where I used a similar code to iterate over all possible values.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Right, same logic as the example

B4X:
Sub btnAutoExposure_Click
    Dim flashes As List = cam.SupportedAutoExposureModes
    Dim i As Int = flashes.IndexOf(cam.AutoExposureMode)
    i = (i + 1) Mod flashes.Size
    cam.AutoExposureMode = flashes.Get(i)
    btnAutoExposure.Text = flashes.Get(i)
    cam.StartPreview(MyTaskIndex, VideoMode)
End Sub

It iterates through the capture sizes, it works. In my phone, it changes the size of the pictures taken.
 
Upvote 0
Top