VFW is old school and will not handle "modern" webcam resolution above 640 or access due to compression methods. Is there sample code to work with these newer Win and Webcams? Sample code for Quartz DirectShow or other available?
Printable View
VFW is old school and will not handle "modern" webcam resolution above 640 or access due to compression methods. Is there sample code to work with these newer Win and Webcams? Sample code for Quartz DirectShow or other available?
You could use the CameraCaptureUI Class.
Since it's a WinRT class, it requires the WinRT TypeLib, everything should be pretty straightforward.Quote:
The Windows.Media.Capture.CameraCaptureUI class provides a built-in, full-window camera user interface for Windows applications. It allows developers to quickly capture photos or videos without having to design custom UI elements or manage low-level camera hardware.
There's Quartz-based samples if you search the forum but that's nearly as old as VFW. Media Foundation would be the option if you didn't want to use RT. -Franky- made a sample if you don't mind DispCallFunc hell, or just tell an LLM to make a sample and it should only need minor changes to work with oleexp.tlb (or WDL in twinBASIC).
I've just included a Camera Capture project in the WinRT Sample Collection linked in the same thread. This project shows a live video preview from your webcam in a PictureBox. A ComboBox lists all available resolutions and video encoding properties supported by your camera and you can switch between them. The aptly named Snapshot button saves a JPG snapshot in the current folder.
Attachment 196209
The form is resizable and the live preview will be automatically resized accordingly. My Windows tablet has a crappy camera so that's what you see in the screenshot above. Professional webcams should support more advanced formats and video compression properties.
This is all it takes to initialize the live camera preview in Form_Load. The WinRT TypeLib makes everything very straight forward using the friendly and familiar VB6 syntax you are already accustomed with:
Code:Private Sub Form_Load()
Dim DesktopWindowXamlSourceNative As IDesktopWindowXamlSourceNative, CaptureElement As ICaptureElement, MediaCaptureInitializationSettings As IMediaCaptureInitializationSettings, _
MediaCaptureVideoPreview As IMediaCaptureVideoPreview
Set m_DesktopWindowXamlSource = NewObject("DesktopWindowXamlSource"): Set DesktopWindowXamlSourceNative = m_DesktopWindowXamlSource: Set m_Await = New cAwait
With DesktopWindowXamlSourceNative
If .AttachToWindow(picCapture.hWnd) = S_OK Then
m_hWndIsland = .WindowHandle
Set CaptureElement = NewObject("CaptureElement"): Set m_DesktopWindowXamlSource.Content = CaptureElement
Set m_MediaCapture = NewObject("MediaCapture"): Set MediaCaptureInitializationSettings = NewObject("MediaCaptureInitializationSettings")
MediaCaptureInitializationSettings.StreamingCaptureMode = StreamingCaptureMode_Video: MediaCaptureInitializationSettings.PhotoCaptureSource = PhotoCaptureSource_VideoPreview
With m_Await
If .Await(m_MediaCapture.InitializeWithSettingsAsync(MediaCaptureInitializationSettings)) = AsyncStatus_Completed Then
Set CaptureElement.Source = m_MediaCapture: CaptureElement.Stretch = Stretch_UniformToFill: Set MediaCaptureVideoPreview = m_MediaCapture
If .Await(MediaCaptureVideoPreview.StartPreviewAsync) = AsyncStatus_Completed Then
Set m_ImageEncodingProperties = ImageEncodingPropertiesStatics.CreateJpeg: EnumerateSupportedResolutions m_MediaCapture.VideoDeviceController
End If
Else
MsgBox Hex$(.ErrorCode) & vbNewLine & .ErrorDescription, vbOKOnly + vbExclamation, App.Title
End If
End With
End If
End With
End Sub
I once wrote an example using Media Foundation, and it was quite a complex undertaking. If I ever had to write something like that again, I would switch to WinRT because it is much easier there. The only downside is that WinRT is only available from Windows 10 onwards, whereas Media Foundation can be used for this purpose starting with Windows 7.