/// <summary> /// Captures the screen. /// </summary> /// <returns>A framebuffer corresponding to the screen.</returns> public VncFramebuffer Capture() { var bounds = this.getScreenBounds(); int w = bounds.Width, h = bounds.Height; if (this.bitmap == null || this.bitmap.Width != w || this.bitmap.Height != h) { this.bitmap = new Bitmap(w, h); this.framebuffer = new VncFramebuffer(this.name, w, h, new VncPixelFormat()); } using (var g = Graphics.FromImage(this.bitmap)) { g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size); lock (this.framebuffer.SyncRoot) { VncBitmap.CopyToFramebuffer( this.bitmap, new VncRectangle(0, 0, w, h), this.framebuffer, 0, 0); } } return(this.framebuffer); }
/// <inheritdoc/> public VncFramebuffer Capture() { int colorIndex = this.random.Next(this.colors.Length); if (this.colors[colorIndex] + this.increments[colorIndex] < byte.MinValue || this.colors[colorIndex] + this.increments[colorIndex] > byte.MaxValue) { this.increments[colorIndex] *= -1; } this.colors[colorIndex] = (byte)(this.colors[colorIndex] + this.increments[colorIndex]); var color = Color.FromArgb(this.colors[0], this.colors[1], this.colors[2]); using (Bitmap image = new Bitmap(this.width, this.height)) using (Graphics gfx = Graphics.FromImage(image)) using (SolidBrush brush = new SolidBrush(color)) using (var font = new Font(FontFamily.GenericSansSerif, 12.0f, FontStyle.Bold, GraphicsUnit.Pixel)) { gfx.FillRectangle(brush, 0, 0, image.Width, image.Height); var text = $"RemoteViewing {ThisAssembly.AssemblyInformationalVersion}"; var size = gfx.MeasureString(text, font); var position = new PointF((image.Width - size.Width) / 2.0f, (image.Height - size.Height) / 2.0f); gfx.DrawString( text, font, Brushes.Black, position); if (this.framebuffer == null || this.framebuffer.Width != image.Width || this.framebuffer.Height != image.Height) { this.framebuffer = new VncFramebuffer("Quamotion", image.Width, image.Height, new VncPixelFormat()); } lock (this.framebuffer.SyncRoot) { VncBitmap.CopyToFramebuffer( image, new VncRectangle(0, 0, image.Width, image.Height), this.framebuffer, 0, 0); } return(this.framebuffer); } }
/// <inheritdoc/> public VncFramebuffer Capture() { int colorIndex = this.random.Next(this.colors.Length); if (this.colors[colorIndex] + this.increments[colorIndex] < byte.MinValue || this.colors[colorIndex] + this.increments[colorIndex] > byte.MaxValue) { this.increments[colorIndex] *= -1; } this.colors[colorIndex] = (byte)(this.colors[colorIndex] + this.increments[colorIndex]); var color = Color.FromArgb(this.colors[0], this.colors[1], this.colors[2]); using (Bitmap image = new Bitmap(400, 400)) using (Graphics gfx = Graphics.FromImage(image)) using (SolidBrush brush = new SolidBrush(color)) { gfx.FillRectangle(brush, 0, 0, image.Width, image.Height); if (this.framebuffer == null || this.framebuffer.Width != image.Width || this.framebuffer.Height != image.Height) { this.framebuffer = new VncFramebuffer("Quamotion", image.Width, image.Height, new VncPixelFormat()); } lock (this.framebuffer.SyncRoot) { VncBitmap.CopyToFramebuffer( image, new VncRectangle(0, 0, image.Width, image.Height), this.framebuffer, 0, 0); } return(this.framebuffer); } }