public void Render(RenderingContext context) { if (!this.IsOpened) { throw new InvalidOperationException(); } Bitmap bitmap = context.Bitmap; Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); Rectangle trackBounds = context.Bounds; BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.WriteOnly, bitmap.PixelFormat); try { int hr = ScreenshotInterop.SSTake(this.pScreenshot, trackBounds.X, trackBounds.Y, bitmapData.Scan0); if (hr != 0) { throw new ScreenException(hr, string.Format("Screenshot.Take failed: {0} (error code = 0x{1:X8}).", GetErrorMessage(hr), hr)); } } finally { bitmap.UnlockBits(bitmapData); } }
public void Render(RenderingContext context) { context.Graphics.DrawImage(this.bitmap, this.bounds.X, this.bounds.Y); }
public void Render() { if (!opened) { throw new InvalidOperationException(); } Graphics graphics = null; try { // Create graphics object graphics = Graphics.FromImage(this.bitmap); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; // Bitmap is upside-down, so transform graphics... graphics.TranslateTransform(0, this.bitmap.Size.Height - 1); graphics.ScaleTransform(1, -1); // Notify display elements that a render is going to happen foreach (IDisplayElement displayElement in this.displayElements) { displayElement.Prepare(graphics); } // Render display elements RenderingContext context = new RenderingContext(this.bitmap, graphics, this.tracker.Bounds); foreach (IDisplayElement displayElement in this.displayElements) { displayElement.Render(context); } } finally { // Notify display elements that render is done foreach (IDisplayElement displayElement in this.displayElements) { displayElement.Unprepare(); } if (graphics != null) { graphics.Dispose(); } } }