Android Code Snippet CameraEx : get smallest possible size

some times you want to take the smallest image size with CameraEx
this sub did the trick
B4X:
Sub setminpicturesize
    Dim x,y As Int
    Dim x2 As Int=1000000
    Dim y2 As Int=1000000
    Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
    For i = 0 To pictureSizes.Length - 1
        x=pictureSizes(i).Width
        y=pictureSizes(i).Height
        If x2>x Then
            x2=x
            y2=y
        End If
    Next
    camEx.SetPictureSize(x2,y2)
    'ToastMessageShow(x2 & "/" & y2, False)
    camEx.CommitParameters
End Sub
* above x2 and y2 initial value equal million, because there is no camera width or height equal million
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Better to check the actual size, not just the width:
B4X:
Dim x2, y2, size As Int
For Each PictureSize As CameraSize In camEx.GetSupportedPicturesSizes
 Dim TempSize As Int = Sqrt(Power(PictureSize.Width, 2) + Power(PictureSize.Height, 2))
 If size = 0 OR TempSize < size Then
  x2 = PictureSize.Width
  y2 = PictureSize.Height
  size = TempSize
End If
Next
 

peacemaker

Expert
Licensed User
Longtime User
My code is:
B4X:
Sub Find_MaxPreviewSize
    Dim sizes() As CameraSize = camEx.GetSupportedPreviewSizes
    videoW = Max(sizes(0).Width, sizes(sizes.Length - 1).Width)
    videoH = Max(sizes(0).Height, sizes(sizes.Length - 1).Height)
    Log("PreviewSize=" & videoW & "x" & videoH)
End Sub

Sub Find_MaxCaptureSize
    Dim sizes() As CameraSize = camEx.GetSupportedPicturesSizes
    videoWmax = Max(sizes(0).Width, sizes(sizes.Length - 1).Width)
    videoHmax = Max(sizes(0).Height, sizes(sizes.Length - 1).Height)
    Log("CaptureSize=" & videoWmax & "x" & videoHmax)
End Sub

It seemed to be that some devices may return the sizes list sorted by ASC or DESC, not the always same kind.
 
Top