public void SendScreenshotResponse(Screenshot screenshot) { if (this._requestId != null && screenshot != null && screenshot.RequestId == this._requestId.Value) { if (this._completeScreenshot != null) { this._completeScreenshot(screenshot); } } }
protected void ProcessCapture(RetrieveImageDataParams data) { var screenshot = new Screenshot(data.RequestId, data.Data, data.Width, data.Height, data.Pitch); try { this.Interface.SendScreenshotResponse(screenshot); } catch (RemotingException ex) { this.TraceMessage("RemotingException: " + ex.Message); screenshot.Dispose(); // Ignore remoting exceptions // .NET Remoting will throw an exception if the host application is unreachable } catch (Exception e) { this.DebugMessage(e.ToString()); } finally { } }
protected void SendResponse(Screenshot response) { System.Threading.Tasks.Task.Factory.StartNew(() => { try { Interface.SendScreenshotResponse(response); LastCaptureTime = Timer.Elapsed; } catch (RemotingException) { // Ignore remoting exceptions // .NET Remoting will throw an exception if the host application is unreachable } catch (Exception e) { DebugMessage(e.ToString()); } }); }
public ScreenshotReceivedEventArgs(Int32 processId, Screenshot screenshot) { ProcessId = processId; Screenshot = screenshot; }
/// <summary> /// Process the capture based on the requested format. /// </summary> /// <param name="width">image width</param> /// <param name="height">image height</param> /// <param name="pitch">data pitch (bytes per row)</param> /// <param name="format">target format</param> /// <param name="pBits">IntPtr to the image data</param> /// <param name="request">The original requets</param> protected void ProcessCapture(int width, int height, int pitch, PixelFormat format, IntPtr pBits, ScreenshotRequest request) { if (request == null) return; if (format == PixelFormat.Undefined) { DebugMessage("Unsupported render target format"); return; } // Copy the image data from the buffer int size = height * pitch; var data = new byte[size]; Marshal.Copy(pBits, data, 0, size); // Prepare the response Screenshot response = null; if (request.Format == Capture.Interface.ImageFormat.PixelData) { // Return the raw data response = new Screenshot(request.RequestId, data) { Format = request.Format, PixelFormat = format, Height = height, Width = width, Stride = pitch }; } else { // Return an image using (var bm = data.ToBitmap(width, height, pitch, format)) { System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Bmp; switch (request.Format) { case Capture.Interface.ImageFormat.Jpeg: imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg; break; case Capture.Interface.ImageFormat.Png: imgFormat = System.Drawing.Imaging.ImageFormat.Png; break; } response = new Screenshot(request.RequestId, bm.ToByteArray(imgFormat)) { Format = request.Format, Height = bm.Height, Width = bm.Width }; } } // Send the response SendResponse(response); }