internal void SetNuevaImagen(ImagenChangedEventArgs e) { if (PictureBox.CheckAccess()) { Byte[] bytes = new Byte[Peer2PeerApp.Comunicacion.AyudanteImagen.MAX_IMAGE_SIZE]; int posicionCursor = 0; int valor = 0; do { if (e.Packet.stream.CanRead) { valor = e.Packet.stream.Read(bytes, posicionCursor, Peer2PeerApp.Comunicacion.AyudanteImagen.MAX_IMAGE_SIZE - posicionCursor); posicionCursor += valor; } else { throw new ApplicationException("Ha sido imposible cargar la imagen. Por favor, inténtelo de nuevo. Si el error persiste reinicie la aplicación."); } } while (valor != 0); try { MemoryStream ms = new MemoryStream(); ms.Write(bytes, 0, posicionCursor); ms.Position = 0; System.Windows.Media.Imaging.BitmapImage bim = new System.Windows.Media.Imaging.BitmapImage(); bim.BeginInit(); bim.StreamSource = ms; bim.EndInit(); PictureBox.Source = bim; Utilidades.SetTextoTextBlock(TextBlockNombreImagen, e.Packet.nombreArchivo); if (ImagenRecibida != null) { ImagenRecibida(this, e); } } catch (NotSupportedException) { //archivo no es .jpg,.gif,.png } } else { PictureBox.Dispatcher.Invoke(DispatcherPriority.Normal, new _SetNuevaImagenHandler(SetNuevaImagen), e); } }