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


Reply With Quote