Results 1 to 3 of 3

Thread: Scanning barcodes in win10 with Surface Pro 6

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Question Scanning barcodes in win10 with Surface Pro 6

    I'm trying to implement barcode scanning with vb on a Surface Pro 6.
    I found this snippet online. Is it possible to get this working in a winforms app?
    If so, what references and imports or nuget packages do i need?

    Thanks for the help...

    Code:
    Private Async Sub StartPreview_Click(ByVal sender As Object, ByVal e As EventArgs)
        'var resultCamera = await GetMediaCapture();
    
        Dim location As Windows.Devices.Enumeration.Panel = Windows.Devices.Enumeration.Panel.Back
    
        Dim cameras = Await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)
    
        For Each camera In cameras
            If camera.EnclosureLocation.Panel Is location Then
                Dim mcs = New MediaCaptureInitializationSettings()
                mcs.VideoDeviceId = camera.Id
                mcs.PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                mcs.StreamingCaptureMode = StreamingCaptureMode.Video
                Dim mc = New MediaCapture()
                Await mc.InitializeAsync(mcs)
    
                VideoStream.Source = mc
                Await mc.StartPreviewAsync()
                mc.SetPreviewMirroring(False)
                ShowSettings.Visibility = Visibility.Visible
                StartPreview.IsEnabled = False
    
                Dim properties = mc.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview)
    
                Dim videoEncodingProperties = TryCast(properties, VideoEncodingProperties)
                If videoEncodingProperties IsNot Nothing Then
                    Dim writeableBitmap = New WriteableBitmap(CInt(videoEncodingProperties.Width), CInt(videoEncodingProperties.Height))
    
                    Await Task.Delay(1000)
    
                    Dim barCodeNotFound As Boolean = True
    
                    Do While barCodeNotFound
                        stream.Seek(0)
                        Await mc.CapturePhotoToStreamAsync(imageEncoding, stream)
    
                        stream.Seek(0)
    
                        Await writeableBitmap.SetSourceAsync(stream)
    
                        Dim result = ScanBitmap(writeableBitmap)
                        If result IsNot Nothing Then
                            ScanResult.Text = result.Text
                            barCodeNotFound = False
                            Await mc.StopPreviewAsync()
                            mc = Nothing
                            previewStarted = False
                            VideoStream.Source = Nothing
                            StartPreview.IsEnabled = True
                        End If
                    Loop
                End If
    
                ' return mc;
            End If
        Next camera
    End Sub

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,398

    Re: Scanning barcodes in win10 with Surface Pro 6

    I have worked with scanning barcodes in the past using Cognex equipment in Windows 10 (can't remember the machine information though)

    Are you looking to essentially take a picture of the barcode using the tablet's camera and then have OCR read the barcode? Or do you plan on using some sort of barcode reader that sends the information to your application?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Scanning barcodes in win10 with Surface Pro 6

    As far as I can tell from the snippet, (it was something someone wrote for a surface pro) the tablet back camera scans the barcode and returns the text. It was originally c# code that I ran through a converter. Looks like WPF to me, but I’m hoping it isn’t, as I have a vb2017 winforms app that I’m trying to extend, and the code apparently does what I need it to…

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width