Android Question Barcode reader based on Google Play Services Vision

JCO

Active Member
Licensed User
Longtime User
Hello,

I would like to use the "Barcode reader based on Google Play Services Vision", but when I download the attached zip, I don't see anything related to barcodes.
I don't know if I'm just being thick, or if there's a miss-match with the attached file.
Could someone please let me know if I'm missing something obvious?

Thanks,
 

DonManfred

Expert
Licensed User
Longtime User
have you run the example? Or had a look at the code? Seems that not.
 
Upvote 0

JCO

Active Member
Licensed User
Longtime User
These are the files as they downloaded from the link:
Main:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: False
    #ApplicationLabel: Camera example
    #VersionCode: 100
    #VersionName: 1.00
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    Private frontCamera As Boolean = False
End Sub

Sub Globals
    Private Panel1 As Panel
    Private camEx As CameraExClass
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume()
    InitializeCamera
End Sub

Private Sub InitializeCamera()
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
        frontCamera = camEx.Front
    Else
        ToastMessageShow("No permission!!!", True)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If camEx.IsInitialized Then
        camEx.Release
    End If
End Sub

Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.SetJpegQuality(90)
        camEx.SetContinuousAutoFocus
        camEx.CommitParameters
        camEx.StartPreview
        Log(camEx.GetPreviewSize)
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

Sub btnTakePicture_Click
    camEx.TakePicture
End Sub

Sub btnFocus_Click
    camEx.FocusAndTakePicture
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirInternal
    
    camEx.SavePictureToFile(Data, dir, filename)
    camEx.StartPreview 'restart preview
    ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
End Sub


Sub ChangeCamera_Click
    camEx.Release
    frontCamera = Not(frontCamera)
    InitializeCamera
End Sub

Sub btnEffect_Click
    Dim effects As List = camEx.GetSupportedColorEffects
    If effects.IsInitialized = False Then
        ToastMessageShow("Effects not supported.", False)
        Return
    End If
    Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
    camEx.SetColorEffect(effect)
    ToastMessageShow(effect, False)
    camEx.CommitParameters
End Sub

Sub btnFlash_Click
    Dim f() As Float = camEx.GetFocusDistances
    Log(f(0) & ", " & f(1) & ", " & f(2))
    Dim flashModes As List = camEx.GetSupportedFlashModes
    If flashModes.IsInitialized = False Then
        ToastMessageShow("Flash not supported.", False)
        Return
    End If
    Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
    camEx.SetFlashMode(flash)
    ToastMessageShow(flash, False)
    camEx.CommitParameters   
End Sub

Sub btnPictureSize_Click
    Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
    Dim current As CameraSize = camEx.GetPictureSize
    For i = 0 To pictureSizes.Length - 1
        If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
    Next
    Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
    camEx.SetPictureSize(ps.Width, ps.Height)
    ToastMessageShow(ps.Width & "x" & ps.Height, False)
    camEx.CommitParameters       
End Sub


Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
    If UserChanged = False Or camEx.IsZoomSupported = False Then Return
    camEx.Zoom = Value / 100 * camEx.GetMaxZoom
    camEx.CommitParameters
End Sub


CameraEx:
'Class module
'version 1.30
'See this page for the list of constants:
'http://developer.android.com/intl/fr/reference/android/hardware/Camera.Parameters.html
'Note that you should use the constant values instead of the names.
Sub Class_Globals
    Private nativeCam As Object
    Private cam As Camera
    Private r As Reflector
    Private target As Object
    Private event As String
    Public Front As Boolean
    Type CameraInfoAndId (CameraInfo As Object, Id As Int)
    Type CameraSize (Width As Int, Height As Int)
    Private parameters As Object
End Sub

Public Sub Initialize (Panel1 As Panel, FrontCamera As Boolean, TargetModule As Object, EventName As String)
    target = TargetModule
    event = EventName
    Front = FrontCamera
    Dim id As Int
    id = FindCamera(Front).id
    If id = -1 Then
        Front = Not(Front) 'try different camera
        id = FindCamera(Front).id
        If id = -1 Then
            ToastMessageShow("No camera found.", True)
            Return
        End If
    End If
    cam.Initialize2(Panel1, "camera", id)
End Sub

Private Sub FindCamera (frontCamera As Boolean) As CameraInfoAndId
    Dim ci As CameraInfoAndId
    Dim cameraInfo As Object
    Dim cameraValue As Int
    Log("findCamera")
    If frontCamera Then cameraValue = 1 Else cameraValue = 0
    cameraInfo = r.CreateObject("android.hardware.Camera$CameraInfo")
    Dim numberOfCameras As Int = r.RunStaticMethod("android.hardware.Camera", "getNumberOfCameras", Null, Null)
    Log(r.target)
    Log(numberOfCameras)
    For i = 0 To numberOfCameras - 1
        r.RunStaticMethod("android.hardware.Camera", "getCameraInfo", Array As Object(i, cameraInfo), _
            Array As String("java.lang.int", "android.hardware.Camera$CameraInfo"))
        r.target = cameraInfo
        Log("facing: " & r.GetField("facing") & ", " & cameraValue)
        If r.GetField("facing") = cameraValue Then
            ci.cameraInfo = r.target
            ci.Id = i
            Return ci
        End If
    Next
    ci.id = -1
    Return ci
End Sub

Private Sub SetDisplayOrientation
    r.target = r.GetActivity
    r.target = r.RunMethod("getWindowManager")
    r.target = r.RunMethod("getDefaultDisplay")
    r.target = r.RunMethod("getRotation")
    Dim previewResult, result, degrees As Int = r.target * 90
    Dim ci As CameraInfoAndId = FindCamera(Front)
    r.target = ci.CameraInfo
    Dim orientation As Int = r.GetField("orientation")
    If Front Then
        previewResult = (orientation + degrees) Mod 360
        result = previewResult
        previewResult = (360 - previewResult) Mod 360
    Else
        previewResult = (orientation - degrees + 360) Mod 360
        result = previewResult
        Log(previewResult)
    End If
    r.target = nativeCam
    r.RunMethod2("setDisplayOrientation", previewResult, "java.lang.int")
    r.target = parameters
    r.RunMethod2("setRotation", result, "java.lang.int")
    CommitParameters
End Sub

Private Sub Camera_Ready (Success As Boolean)
    If Success Then
        r.target = cam
        nativeCam = r.GetField("camera")
        r.target = nativeCam
        parameters = r.RunMethod("getParameters")
        SetDisplayOrientation
    Else
        Log("success = false, " & LastException)
    End If
    CallSub2(target, event & "_ready", Success)
End Sub
'Uncomment this sub if you need to handle the Preview event
'Sub Camera_Preview (Data() As Byte)
'    If SubExists(target, event & "_preview") Then
'        CallSub2(target, event & "_preview", Data)
'    End If
'End Sub

Public Sub TakePicture
    cam.TakePicture
End Sub

Private Sub Camera_PictureTaken (Data() As Byte)
    CallSub2(target, event & "_PictureTaken", Data)
End Sub

Public Sub StartPreview
    cam.StartPreview
End Sub

Public Sub StopPreview
    cam.StopPreview
End Sub

Public Sub Release
    cam.Release
End Sub

'Saves the data received from PictureTaken event
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)
    out.Close
End Sub

Public Sub SetParameter(Key As String, Value As String)
    r.target = parameters
    r.RunMethod3("set", Key, "java.lang.String", Value, "java.lang.String")
End Sub

Public Sub GetParameter(Key As String) As String
    r.target = parameters
    Return r.RunMethod2("get", Key, "java.lang.String")
End Sub

Public Sub CommitParameters
    'Try
        r.target = nativeCam
        r.RunMethod4("setParameters", Array As Object(parameters), Array As String("android.hardware.Camera$Parameters"))
    'Catch
'        ToastMessageShow("Error setting parameters.", True)
'        Log(LastException)
'    End Try
End Sub

Public Sub GetColorEffect As String
    Return GetParameter("effect")
End Sub

Public Sub SetColorEffect(Effect As String)
    SetParameter("effect", Effect)
End Sub

Public Sub GetSupportedPreviewSizes As CameraSize()
    r.target = parameters
    Dim list1 As List = r.RunMethod("getSupportedPreviewSizes")
    Dim cs(list1.Size) As CameraSize
    For i = 0 To list1.Size - 1
        r.target = list1.get(i)
        cs(i).Width = r.GetField("width")
        cs(i).Height = r.GetField("height")
    Next
    Return cs
End Sub

Public Sub SetPreviewSize(Width As Int, Height As Int)
    r.target = parameters
    r.RunMethod3("setPreviewSize", Width, "java.lang.int", Height, "java.lang.int")
End Sub
Public Sub GetSupportedPicturesSizes As CameraSize()
    r.target = parameters
    Dim list1 As List = r.RunMethod("getSupportedPictureSizes")
    Dim cs(list1.Size) As CameraSize
    For i = 0 To list1.Size - 1
        r.target = list1.get(i)
        cs(i).Width = r.GetField("width")
        cs(i).Height = r.GetField("height")
    Next
    Return cs
End Sub

Public Sub SetPictureSize(Width As Int, Height As Int)
    r.target = parameters
    r.RunMethod3("setPictureSize", Width, "java.lang.int", Height, "java.lang.int")
End Sub

Public Sub SetJpegQuality(Quality As Int)
    r.target = parameters
    r.RunMethod2("setJpegQuality", Quality, "java.lang.int")
End Sub

Public Sub SetFlashMode(Mode As String)
    r.target = parameters
    r.RunMethod2("setFlashMode", Mode, "java.lang.String")
End Sub

Public Sub GetFlashMode As String
    r.target = parameters
    Return r.RunMethod("getFlashMode")
End Sub

Public Sub GetSupportedFlashModes As List
    r.target = parameters
    Return r.RunMethod("getSupportedFlashModes")
End Sub

Public Sub GetSupportedColorEffects As List
    r.target = parameters
    Return r.RunMethod("getSupportedColorEffects")
End Sub

'Returns a list with the supported preview fps. Each item in the list is an array of two ints (minimum value and maximum value).
Public Sub GetSupportedPreviewFpsRange As List
    r.target = parameters
    Return r.RunMethod("getSupportedPreviewFpsRange")
End Sub
'Returns the current preview fps range.
'Range is a two elements array. The minimum value and maximum value will be stored in this array.
Public Sub GetPreviewFpsRange(Range() As Int)
    r.target = parameters
    r.RunMethod4("getPreviewFpsRange", Array As Object(Range), Array As String("[I"))
End Sub

Public Sub SetPreviewFpsRange(MinValue As Int, MaxValue As Int)
    r.target = parameters
    r.RunMethod4("setPreviewFpsRange", Array As Object(MinValue, MaxValue), _
        Array As String("java.lang.int", "java.lang.int"))
End Sub

Public Sub GetPreviewSize As CameraSize
    r.target = parameters
    r.target = r.RunMethod("getPreviewSize")
    Dim cs As CameraSize
    cs.Width = r.GetField("width")
    cs.Height = r.GetField("height")
    Return cs
End Sub

Public Sub GetPictureSize As CameraSize
    r.target = parameters
    r.target = r.RunMethod("getPictureSize")
    Dim cs As CameraSize
    cs.Width = r.GetField("width")
    cs.Height = r.GetField("height")
    Return cs
End Sub

'Converts a preview image formatted in YUV format to JPEG.
'Note that you should not save every preview image as it will slow down the whole process.
Public Sub PreviewImageToJpeg(data() As Byte, quality As Int) As Byte()
    Dim size, previewFormat As Object
    r.target = parameters
    size = r.RunMethod("getPreviewSize")
    previewFormat = r.RunMethod("getPreviewFormat")
    r.target = size
    Dim width = r.GetField("width"), height = r.GetField("height") As Int
    Dim yuvImage As Object = r.CreateObject2("android.graphics.YuvImage", _
        Array As Object(data, previewFormat, width, height, Null), _
        Array As String("[B", "java.lang.int", "java.lang.int", "java.lang.int", "[I"))
    r.target = yuvImage
    Dim rect1 As Rect
    rect1.Initialize(0, 0, r.RunMethod("getWidth"), r.RunMethod("getHeight"))
    Dim out As OutputStream
    out.InitializeToBytesArray(100)
    r.RunMethod4("compressToJpeg", Array As Object(rect1, quality, out), _
        Array As String("android.graphics.Rect", "java.lang.int", "java.io.OutputStream"))
    Return out.ToBytesArray
End Sub

Public Sub GetSupportedFocusModes As List
    r.target = parameters
    Return r.RunMethod("getSupportedFocusModes")
End Sub

Public Sub SetContinuousAutoFocus
    Dim modes As List = GetSupportedFocusModes
    If modes.IndexOf("continuous-picture") > -1 Then
        SetFocusMode("continuous-picture")
    Else If modes.IndexOf("continuous-video") > -1 Then
        SetFocusMode("continuous-video")
    Else
        Log("Continuous focus mode is not available")
    End If
End Sub

Public Sub SetFocusMode(Mode As String)
    r.target = parameters
    r.RunMethod2("setFocusMode", Mode, "java.lang.String")
End Sub

Public Sub GetFocusDistances As Float()
    Dim F(3) As Float
    r.target = parameters
    r.RunMethod4("getFocusDistances", Array As Object(F), Array As String("[F"))
    Return F
End Sub

Public Sub GetSupportedPictureFormats As List
    r.target = parameters
    Return r.RunMethod("getSupportedPictureFormats")
End Sub
'This method should only be called if you need to immediately release the camera.
'For example if you need to start another application that depends on the camera.
Public Sub CloseNow
    cam.Release
    r.target = cam
    r.RunMethod2("releaseCameras", True, "java.lang.boolean")
End Sub
'Calls AutoFocus and then takes the picture if focus was successfull.
Public Sub FocusAndTakePicture
    cam.AutoFocus
End Sub


Private Sub Camera_FocusDone (Success As Boolean)
    If Success Then
        TakePicture
    Else
        Log("AutoFocus error.")
    End If
End Sub

Public Sub IsZoomSupported As Boolean
  r.target = parameters
  Return r.RunMethod("isZoomSupported")
End Sub

Public Sub GetMaxZoom As Int
  r.target = parameters
  Return r.RunMethod("getMaxZoom")
End Sub

Public Sub getZoom() As Int
    r.target = parameters
    Return r.RunMethod("getZoom")
End Sub

Public Sub setZoom(ZoomValue As Int)
  r.target = parameters
  r.RunMethod2("setZoom", ZoomValue, "java.lang.int")
End Sub

Public Sub getExposureCompensation As Int
    r.target = parameters
    Return r.RunMethod("getExposureCompensation")
End Sub

Public Sub setExposureCompensation(v As Int)
    r.target = parameters
    r.RunMethod2("setExposureCompensation", v, "java.lang.int")
End Sub

Public Sub getMinExposureCompensation As Int
    r.target = parameters
    Return r.RunMethod("getMinExposureCompensation")
End Sub

Public Sub getMaxExposureCompensation As Int
    r.target = parameters
    Return r.RunMethod("getMaxExposureCompensation")
End Sub

Public Sub SetFaceDetectionListener
    Dim jo As JavaObject = nativeCam
    Dim e As Object = jo.CreateEvent("android.hardware.Camera.FaceDetectionListener", "FaceDetection", Null)
    jo.RunMethod("setFaceDetectionListener", Array(e))
End Sub

Private Sub FaceDetection_Event (MethodName As String, Args() As Object) As Object
    Dim faces() As Object = Args(0)
    For Each f As Object In faces
        Dim jo As JavaObject = f
        Dim faceRect As Rect = jo.GetField("rect")
        Log(faceRect)
    Next
    Return Null
End Sub

Public Sub StartFaceDetection
    Dim jo As JavaObject = nativeCam
    jo.RunMethod("startFaceDetection", Null)
End Sub

Public Sub StopFaceDetection
    Dim jo As JavaObject = nativeCam
    jo.RunMethod("stopFaceDetection", Null)
End Sub

All I need is for someone just point to the line I should be looking at, I'd be very grateful.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
this is the activity code from the example which you do not posted (but it is there in the example)

Again: please have a deep look at the code. There is an AdditionalJar, there is code for barcode initialisation, which barcodes to search.
Also have a look at the manifest.

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: False
    #ApplicationLabel: Camera example
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region
#AdditionalJar: com.google.android.gms:play-services-vision
#BridgeLogger: true
'Activity module
Sub Process_Globals
    Private frontCamera As Boolean = False
    Private detector As JavaObject
    Private SearchForBarcodes As Boolean
    Private LastPreview As Long
    Private IntervalBetweenPreviewsMs As Int = 100
End Sub

Sub Globals
    Private Panel1 As Panel
    Private camEx As CameraExClass
    Private pnlDrawing As Panel
    Private cvs As B4XCanvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    If FirstTime Then
        CreateDetector (Array("CODE_128", "CODE_93"))
    End If
    cvs.Initialize(pnlDrawing)
End Sub

Private Sub CreateDetector (Codes As List)
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim builder As JavaObject
    builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
    Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
    Dim barcodeStatic As JavaObject
    barcodeStatic.InitializeStatic(barcodeClass)
    Dim format As Int
    For Each formatName As String In Codes
        format = Bit.Or(format, barcodeStatic.GetField(formatName))
    Next
    builder.RunMethod("setBarcodeFormats", Array(format))
    detector = builder.RunMethod("build", Null)
    Dim operational As Boolean = detector.RunMethod("isOperational", Null)
    Log("Is detector operational: " & operational)
    SearchForBarcodes = operational
 
End Sub

Sub Camera1_Preview (data() As Byte)
    If SearchForBarcodes Then
        If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
            'Dim n As Long = DateTime.Now
            cvs.ClearRect(cvs.TargetRect)
            Dim frameBuilder As JavaObject
            Dim bb As JavaObject
            bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
            frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
            Dim cs As CameraSize = camEx.GetPreviewSize
            frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height,  842094169))
            Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
            Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
            LastPreview = DateTime.Now
            Dim Matches As Int = SparseArray.RunMethod("size", Null)
            For i = 0 To Matches - 1
                Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(i))
                Dim raw As String = barcode.GetField("rawValue")
                Log(raw)
                ToastMessageShow("Found: " & raw, True)
                Dim points() As Object = barcode.GetField("cornerPoints")
                Dim tl As JavaObject = points(0)
'                Dim tr As JavaObject = points(1)
                Dim br As JavaObject = points(2)
'                Dim bl As JavaObject = points(3)
                Dim r As B4XRect
             
                Dim size As CameraSize = camEx.GetPreviewSize
                Dim xscale, yscale As Float
                If camEx.PreviewOrientation Mod 180 = 0 Then
                    xscale = Panel1.Width / size.Width
                    yscale = Panel1.Height / size.Height
                    r.Initialize(tl.GetField("x"), tl.GetField("y"), br.GetField("x"), br.GetField("y"))
                Else
                    xscale = Panel1.Width / size.Height
                    yscale = Panel1.Height / size.Width
                    r.Initialize(br.GetField("y"), br.GetField("x"), tl.GetField("y"),tl.GetField("x"))
                End If
             
                Select camEx.PreviewOrientation
                    Case 180
                        r.Initialize(size.Width - r.Right, size.Height - r.Bottom, size.Width - r.Left, size.Height - r.Top)
                    Case 90
                        r.Initialize(size.Height - r.Right, r.Top, size.Height - r.Left, r.Bottom)
                End Select
                r.Left = r.Left * xscale
                r.Right = r.Right * xscale
                r.Top = r.Top * yscale
                r.Bottom = r.Bottom * yscale
                cvs.DrawRect(r, Colors.Red, False, 5dip)
            Next
            If Matches = 0 Then
                cvs.ClearRect(cvs.TargetRect)
            End If
            cvs.Invalidate
         
            'Log(DateTime.Now - n)
        End If
    End If
End Sub

Sub Activity_Resume
    InitializeCamera
End Sub

Private Sub InitializeCamera
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
        frontCamera = camEx.Front
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If camEx.IsInitialized Then
        camEx.Release
    End If
End Sub

Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camEx.SetJpegQuality(90)
        camEx.SetContinuousAutoFocus
        camEx.CommitParameters
        camEx.StartPreview
     
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub



'Sub btnTakePicture_Click
'    camEx.TakePicture
'End Sub
'
'Sub btnFocus_Click
'    camEx.FocusAndTakePicture
'End Sub

Sub Camera1_PictureTaken (Data() As Byte)
'    Dim filename As String = "1.jpg"
'    Dim dir As String = File.DirRootExternal
'
'    camEx.SavePictureToFile(Data, dir, filename)
'    camEx.StartPreview 'restart preview
'
'    'send a broadcast intent to the media scanner to force it to scan the saved file.
'    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)
'    ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
End Sub

Sub ChangeCamera_Click
    camEx.Release
    frontCamera = Not(frontCamera)
    InitializeCamera
End Sub

Sub btnEffect_Click
    Dim effects As List = camEx.GetSupportedColorEffects
    If effects.IsInitialized = False Then
        ToastMessageShow("Effects not supported.", False)
        Return
    End If
    Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
    camEx.SetColorEffect(effect)
    ToastMessageShow(effect, False)
    camEx.CommitParameters
End Sub

Sub btnFlash_Click
    Dim f() As Float = camEx.GetFocusDistances
    Log(f(0) & ", " & f(1) & ", " & f(2))
    Dim flashModes As List = camEx.GetSupportedFlashModes
    If flashModes.IsInitialized = False Then
        ToastMessageShow("Flash not supported.", False)
        Return
    End If
    Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
    camEx.SetFlashMode(flash)
    ToastMessageShow(flash, False)
    camEx.CommitParameters
End Sub
Sub btnPictureSize_Click
    Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
    Dim current As CameraSize = camEx.GetPictureSize
    For i = 0 To pictureSizes.Length - 1
        If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
    Next
    Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
    camEx.SetPictureSize(ps.Width, ps.Height)
    ToastMessageShow(ps.Width & "x" & ps.Height, False)
    camEx.CommitParameters    
End Sub


Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
    If UserChanged = False Or camEx.IsZoomSupported = False Then Return
    camEx.Zoom = Value / 100 * camEx.GetMaxZoom
    camEx.CommitParameters
End Sub
 
Last edited:
Upvote 0

JCO

Active Member
Licensed User
Longtime User
this is the activity code from the example

Again: PLEASE HAVE A DEEP LOOK AT THIS CODE

Hi Manfred,

Thanks for the time you've taken to help.

Please note that the file you posted is not the same, somehow, the download got messed-up on my PC (cache maybe?) and it was not downloading the correct file (I downloaded it 3 times, just to make sure)
After I saw the code in your message I re-downloaded the file from a different PC, and then I got the same you just posted, which, of course, works fine.

I just want to point out that I never post a question without trying to understand/solve the stuff muself for at least a few hours. In this case, I could have looked at the code for days, I would neve have found it, because my downloads weren't correct.

Thanks again,
Julio
 
Upvote 0
Top