Alla prima proposta di codice dell'autore della discussione, tale
ingo, è possibile dare una risposta efficace e risolutiva.
Il codice della Classe principale sarebbe questo:
Public vc As VideoClass
Public Sub Button1_Click()
If Not Exist("/dev/video0") Then
Message.Info("WebCam non inserita !")
Return
Endif
vc = New VideoClass
vc.drwArea.Refresh()
End
Il codice della Classe secondaria, chiamata "
VideoClass.class" sarebbe questo:
Public hPipe As MediaPipeline
Public hSource As MediaControl
Public hSink As MediaControl
Public hdrwVideo As DrawingArea
Property {drwArea} As DrawingArea
Public Sub _new()
With hdrwVideo = New DrawingArea(fmain)
.X = 0
.Y = 0
.W = FMain.W
.H = 400
.Background = Color.Transparent
End With
hPipe = New MediaPipeline As "hPipe"
hSource = New MediaControl(hPipe, "v4l2src")
hSource["device"] = "/dev/video0"
hSink = New MediaControl(hPipe, "xvimagesink")
hSource.LinkTo(hSink)
hSink.SetWindow(hdrwVideo)
hPipe.Play()
End
Private Function drwArea_Read() As DrawingArea
Return hdrwVideo
End
Private Sub drwArea_Write(Value As DrawingArea)
hdrwVideo = Value
hSink.SetWindow(hdrwVideo)
End