/// <summary> /// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread. /// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks. /// </summary> private static ImageSource GetImageSourceByRenderingOverlay(GraphController controller, GdiToWpfBitmap bmp, CachedGraphImage cachedGraphImage) { if (controller.IsOverlayPaintingRequired) { using (var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp)) { controller.DoPaintOverlay(grfx, cachedGraphImage.ZoomFactor, cachedGraphImage.ViewPortsUpperLeftCornerInGraphCoordinates); return(bmp.WpfBitmapSource); } } else { return(null); } }