public override async Task Draw(EInkCanvas canvas) { var ms1 = new MemoryStream(); var ms2 = new MemoryStream(); try { Console.WriteLine("Rendering Black/White image ..."); canvas.Export(System.Drawing.Imaging.ImageFormat.Bmp, Color.White, ms1); Console.WriteLine("Rendering Red image ..."); canvas.Export(System.Drawing.Imaging.ImageFormat.Bmp, Color.Red, ms2); Console.WriteLine("Rewind!"); ms1.Seek(0, SeekOrigin.Begin); ms2.Seek(0, SeekOrigin.Begin); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("Enter DisplayFrame()"); await this.DisplayFrame( new DirectBitmap((Bitmap)Image.FromStream(ms1)), new DirectBitmap((Bitmap)Image.FromStream(ms2))); }
public static void Create(Control control, EInkCanvas canvas, int pollingIntervalMs) { if (control.Width > canvas.Width || control.Height > canvas.Height) { throw new Exception($"Control must be equal to or smaller than the device's canvas (device canvas is {canvas.Width}x{canvas.Height})"); } var existingControl = _registeredControls.FirstOrDefault(c => c.Control == control); if (existingControl != null) { existingControl.Timer.Stop(); _registeredControls.Remove(existingControl); } var registeredControl = new RegisteredInkControl() { Control = control, Canvas = canvas, Timer = new Timer() { Interval = pollingIntervalMs } }; registeredControl.Timer.Tick += (s, e) => { var bmp = new Bitmap(canvas.Width, canvas.Height); using (Graphics gb = Graphics.FromImage(bmp)) using (Graphics gc = Graphics.FromHwnd(control.Handle)) { IntPtr hdcDest = IntPtr.Zero; IntPtr hdcSrc = IntPtr.Zero; try { hdcDest = gb.GetHdc(); hdcSrc = gc.GetHdc(); // BitBlt copies directly from the gfx buffer; gets around GDI vs DX rendering issues BitBlt(hdcDest, 0, 0, canvas.Width, canvas.Height, hdcSrc, 0, 0, SRC_COPY); } finally { if (hdcDest != IntPtr.Zero) { gb.ReleaseHdc(hdcDest); } if (hdcSrc != IntPtr.Zero) { gc.ReleaseHdc(hdcSrc); } } } canvas.UpdateSurface(bmp); }; registeredControl.Timer.Start(); _registeredControls.Add(registeredControl); }
public override async Task Draw(EInkCanvas canvas) { var packet = new NetPacket(); var inkAction = new InkAction(canvas); // draws packet.Write(inkAction.Serialize()); _client.Send(packet); await Task.Yield(); }
private async Task HandleMessageAsync(InkAction value) { try { switch (value.InkActionType) { case InkAction.InkActionTypes.Reset: await InkHostServer.ActiveDevice.Reset(); break; case InkAction.InkActionTypes.Init: await InkHostServer.ActiveDevice.Init(); break; case InkAction.InkActionTypes.Draw: var canvas = EInkCanvas.ImportJson(value.CanvasJson); Console.WriteLine($"[{this.Id}] Drawing {canvas.AvailableInkColors.Length} colors to {canvas.Width}x{canvas.Height} canvas."); Console.WriteLine($"... {canvas.Width}x{canvas.Height}"); Console.WriteLine($"... Colors: {string.Join(", ", canvas.AvailableInkColors.Select(c => c.Name))}"); await InkHostServer.ActiveDevice.Draw(canvas); break; case InkAction.InkActionTypes.Clear: await InkHostServer.ActiveDevice.Clear(); break; } Console.WriteLine($"[{this.Id}] Action complete."); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void RegisterForInk(this Control control, EInkCanvas canvas, int pollingIntervalMs = 500) { RegisteredInkControl.Create(control, canvas, pollingIntervalMs); }
public InkAction(EInkCanvas canvas) { InkActionType = InkActionTypes.Draw; CanvasJson = canvas.ExportJson(); }
public abstract Task Draw(EInkCanvas canvas);