llevaba muchisimo tiempo sin pasar por aqui (cosas del tiempo disponible),
bueno les comento:
Estoy haciendo un videoChat mediante sockets en WPF con VB.NET (evidentemente Framework 3.5).
Bien la cuestión es que la recepción de la imagen la consigo OK, pero al visualizarla en un control de tipo image, me peta. Este es el código:
Código:
La excepción que obtengo es Targetinvocationexception. Como veis uso delegados, para no tener problemas con cruces de hilos, pero con el objeto de la UI Image, me peta al cambiarle el source.Public Delegate Sub ChangeImageCallback(ByVal texto As String, ByVal img As BitmapImage) Private WithEvents remoteImg As New BitmapImage Private Sub Recepcion() Try ' // Open The Port mytcpl = New TcpListener(text_Camera_rec_port) mytcpl.Start() ' mysocket = mytcpl.AcceptSocket() ns = New NetworkStream(mysocket) Dim myJpg As Image = Bitmap.FromStream(ns) myJpg.Save("c:\Prueba.jpg") 'CON ESTO COMPRUEBO QUE RECIVO LA IMAGEN Y ESTA ES OK Dim img As New BitmapImage img.BeginInit() img.StreamSource = ns img.EndInit() Dim dlg As ChangeImageCallback = New ChangeImageCallback(AddressOf ChangeImage) Dispatcher.BeginInvoke(Windows.Threading.DispatcherPriority.Normal, dlg, "Prueba", img) mytcpl.Stop() If (mysocket.Connected = True) Then While True Recepcion() End While End If Catch ex As Exception End Try End Sub Private Sub ChangeImage(ByVal texto As String, ByVal thisimg As BitmapImage) remoteImg = thisimg lblStatus.Text = texto Cam3.Source = thisimg 'AQUI PETA, SI PONGO SOLO EL .TEXT, LO CAMBIA OK End Sub
¿Alguna idea de que puede estar pasando??