private static void OnReceive(Socket handler) { if (handler != null) { try { byte[] lenBuf = new byte[4]; handler.Receive(lenBuf); int len = BitConverter.ToInt32(lenBuf, 0); byte[] buf = new byte[len]; int trans = 0; while (trans < len) { trans += handler.Receive(buf, trans, len - trans, SocketFlags.None); } if (len > 0) { Image image = ConvertImage(buf); ReceiveImageEventArgs args = new ReceiveImageEventArgs(image); ImageReceived?.Invoke(typeof(ImageServer), args); } } catch (SocketException e) { } } }
/// <summary> /// Handles ImageEvent and invokes ImageReceived. /// </summary> /// <param name="eventtype"></param> /// <param name="size"></param> /// <param name="imageformat"></param> /// <param name="sfimageData"></param> /// <param name="pscannerdata"></param> private void OnImageEvent(short eventtype, int size, short imageformat, ref object sfimageData, ref string pscannerdata) { if (ImageEvent.CaptureCompleted != (ImageEvent)eventtype) { return; } var arr = (Array)sfimageData; var len = arr.LongLength; var byImage = new byte[len]; arr.CopyTo(byImage, 0); var xdoc = XDocument.Parse(pscannerdata); ImageFormat format = null; using (var ms = new MemoryStream(byImage)) { var image = Image.FromStream(ms); if ((Constants.Enums.ImageFormat)imageformat == Constants.Enums.ImageFormat.Bmp) { format = ImageFormat.Bmp; } else if ((Constants.Enums.ImageFormat)imageformat == Constants.Enums.ImageFormat.Jpeg) { format = ImageFormat.Jpeg; } else if ((Constants.Enums.ImageFormat)imageformat == Constants.Enums.ImageFormat.Tiff) { format = ImageFormat.Tiff; } ImageReceived?.Invoke(this, new ImageEventArgs(ParseScannerId(xdoc), format, image)); } }
private async void Watcher_Created(object sender, FileSystemEventArgs e) { await Task.Delay(100); var path = Path.GetFullPath(e.FullPath); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(path); bitmap.EndInit(); bitmap.Freeze(); ImageReceived?.Invoke(this, bitmap); }
public static void Process(CommandFlags flag, BinaryReader reader) { switch (flag) { case CommandFlags.DataCorrupted: Console.WriteLine("Data corrupted. Closing zombie connection"); break; case CommandFlags.GenericCommandOutput: GenericCommandReceived?.Invoke(null, new GenericCommandArgs(reader.ReadString())); break; case CommandFlags.Screenshot: string id = reader.ReadString(); byte[] img = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); ImageReceived?.Invoke(null, new ImageArgs(img, id)); break; case CommandFlags.ChatMessage: MessageReceived?.Invoke(null, new MessageArgs(reader.ReadString(), reader.ReadString())); break; } }
private void client_DownloadImageCompleted(object sender, DownloadDataCompletedEventArgs e) { try { if (e.Error != null) { Logger.WriteError(MethodBase.GetCurrentMethod(), e.Error.Message); return; } if (e.Result != null) { ImageReceived.Invoke(this, e.Result); } } catch (Exception ex) { ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs { Methode = MethodBase.GetCurrentMethod(), Error = ex }); } }
private static void ImageServer_ReceiveImage(object sender, ReceiveImageEventArgs e) { ImageReceived?.Invoke(typeof(ControllerHost), e); }
private void OnImageReceived(Bitmap img) { ImageReceived?.Invoke(img); }
private static void RaisedImageReceived(object sender, HImage image, string info) => ImageReceived?.Invoke(sender, new ImageDataEventArgs(image, info));
private void OnImageReceived(Image image, int frameIndex) => ImageReceived?.Invoke(image, frameIndex);
private async void Socket_MessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { Stream streamIn = args.GetDataStream().AsStreamForRead(); HostName serverAddressFull; using (var reader = new StreamReader(streamIn)) { serverName = await reader.ReadToEndAsync(); serverAddressFull = args.RemoteAddress; serverAddress = serverAddressFull.ToString(); LoggingManager.Log("Detected " + serverName + " (" + serverAddress + "), attempting to establish tcp connection"); } commandSocket = new StreamSocket(); await commandSocket.ConnectAsync(serverAddressFull, commandPort.ToString()); LoggingManager.Log("Tcp connection established, sending handshake"); var commandStreamOut = commandSocket.OutputStream.AsStreamForWrite(); commandOut = new StreamWriter(commandStreamOut, Encoding.UTF8); commandOut.WriteLine(deviceName); commandOut.Flush(); LoggingManager.Log("Handshake sent, establishing video connection"); videoSocket = new StreamSocket(); await videoSocket.ConnectAsync(serverAddressFull, videoPort.ToString()); Connected?.Invoke(); connected = true; LoggingManager.Log("Video connection established, starting new threads"); _ = Task.Run(async() => { try { var commandStreamIn = commandSocket.InputStream.AsStreamForRead(); var reader = new StreamReader(commandStreamIn, Encoding.UTF8); while (true) { string message = await reader.ReadLineAsync(); if (message.Length > 0) { TextReceived?.Invoke(message); //LoggingManager.Log("Received message: " + message); } } } catch { LostConnection?.Invoke(); connected = false; } }); _ = Task.Run(async() => { try { var videoStreamIn = new DataReader(videoSocket.InputStream); videoStreamIn.ByteOrder = ByteOrder.LittleEndian; // need to set this or the bytes will be read in the wrong order videoOut = new DataWriter(videoSocket.OutputStream); videoOut.ByteOrder = ByteOrder.LittleEndian; //byte[] buffer = new byte[640 * 640 * 3]; // load the bytes for the first integer, the image size var count = await videoStreamIn.LoadAsync(4); while (true) { int length = videoStreamIn.ReadInt32(); // first read the image size (in # of bytes) //Debug.Log("Attempting to read image of length " + length); // read the image byte[] buffer = new byte[length]; count = await videoStreamIn.LoadAsync((uint)length); videoStreamIn.ReadBytes(buffer); //ImageReceived?.Invoke(buffer); // convert the bytes to a stream var imgStream = buffer.AsBuffer().AsStream().AsRandomAccessStream(); //Debug.Log("Read image, decoding"); // decode the image var decoder = await BitmapDecoder.CreateAsync(imgStream); imgStream.Seek(0); int width = (int)decoder.PixelWidth; int height = (int)decoder.PixelHeight; var data = await decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, new BitmapTransform(), ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage); var decodedBytes = data.DetachPixelData(); // display the image ImageReceived?.Invoke(decodedBytes, width, height); //Debug.Log("Received image"); // clean up memory buffer = null; data = null; decodedBytes = null; GC.GetTotalMemory(true); // start to read the next image count = await videoStreamIn.LoadAsync(4); } } catch { LostConnection?.Invoke(); connected = false; } }); }
/// <summary> /// Handle Image-Reception /// </summary> /// <param name="e"></param> public void OnImageReceived(FaceWatcherEventArgs e) { ImageReceived?.Invoke(this, e); }
public virtual void OnImageReceived(EventArgs e) { ImageReceived?.Invoke(this, e); }