void _viewer_PostRender(object sender, ImageViewerRenderEventArgs args) { LeadPoint firstPoint = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadPoint.Create(_xStart, _yStart)); LeadPoint endPoint = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadPoint.Create(_xEnd, _yEnd)); float[] dashValuesWhite = { 4, 4, 4, 4 }; Pen penBlack = new Pen(Color.Black, 1); Pen penWhite = new Pen(Color.White, 1); PaintEventArgs e = args.PaintEventArgs; penWhite.DashPattern = dashValuesWhite; e.Graphics.DrawLine(penBlack, firstPoint.X, firstPoint.Y, endPoint.X, endPoint.Y); e.Graphics.DrawLine(penWhite, firstPoint.X, firstPoint.Y, endPoint.X, endPoint.Y); LeadRect startRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadRect.Create(_startRect.X, _startRect.Y, _startRect.Width, _startRect.Height)); LeadRect endRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadRect.Create(_endRect.X, _endRect.Y, _endRect.Width, _endRect.Height)); if (_cbMovable.Checked) { e.Graphics.DrawRectangle(penBlack, startRect.X, startRect.Y, startRect.Width, startRect.Height); e.Graphics.DrawRectangle(penWhite, startRect.X, startRect.Y, startRect.Width, startRect.Height); e.Graphics.DrawRectangle(penBlack, endRect.X, endRect.Y, endRect.Width, endRect.Height); e.Graphics.DrawRectangle(penWhite, endRect.X, endRect.Y, endRect.Width, endRect.Height); } }
private void AutomationRasterImageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { var engine = _engine as AnnDrawRenderingEngine; if (engine == null || e.SurfaceContext == null) { return; } // Render all containers if (_getContainersCallback != null) { // Using multi-containers AnnContainerCollection containers = _getContainersCallback(); foreach (AnnContainer container in containers) { RenderContainer(e, engine, container); } } else { // Using single-containers, just render the active RenderContainer(e, engine, _container); } }
private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { RasterImage image = _imageViewer.Image; if (image == null || _overlayRect.IsEmpty) { // No image or the overlay rectangle hasn't been set yet return; } // Convert the overlay rectangle (it is in image coordinates) to viewer coordinates LeadRect imageRect = LeadRect.Create(_overlayRect.X, _overlayRect.Y, _overlayRect.Width, _overlayRect.Height); // We must pass false for 'accountForViewPerspective' in this case because _overlayRect is always // in top-left coordinates in this demo LeadRect viewerRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, imageRect); if (!viewerRect.IsEmpty) { // Otherwise, we zoomed out too much and it is too small to paint Graphics g = e.PaintEventArgs.Graphics; using (Brush brush = new SolidBrush(Color.FromArgb(128, Color.Black))) { Rectangle rect = Rectangle.FromLTRB(viewerRect.Left, viewerRect.Top, viewerRect.Right, viewerRect.Bottom); g.FillRectangle(brush, rect); g.DrawRectangle(Pens.Yellow, viewerRect.X, viewerRect.Y, viewerRect.Width - 1, viewerRect.Height - 1); } } }
private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { foreach (FormFieldControl control in _imageViewer.Controls) { control.Invalidate(); } }
private void _ImageList_Paint(object sender, ImageViewerRenderEventArgs e) { // Draw the letter R on each recognized page LeadSize itemImageSize = _ImageList.ItemSize; Graphics g = e.PaintEventArgs.Graphics; using (Brush textBrush = new SolidBrush(Color.FromArgb(128, Color.Black))) { foreach (ImageViewerItem item in _ImageList.Items) { bool isPageRecognized = false; if (item.Tag != null) { isPageRecognized = (bool)item.Tag; } if (isPageRecognized) { LeadRectD itemRect = _ImageList.GetItemBounds(item, ImageViewerItemPart.Image); var transform = _ImageList.GetItemImageTransform(item); itemRect.X = transform.OffsetX; itemRect.Y = transform.OffsetY; SizeF textSize = g.MeasureString("R", _ImageList.Font); RectangleF textRect = new RectangleF((float)itemRect.X + 2, (float)itemRect.Y + 2, textSize.Width, textSize.Height); g.FillRectangle(textBrush, textRect); g.DrawString("R", _ImageList.Font, Brushes.White, textRect.Location); } } } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs args) { PaintEventArgs e = args.PaintEventArgs; if (command != null) { if (_drawing) { double xFactor = _viewer.XScaleFactor; double yFactor = _viewer.YScaleFactor; float xOffset = -_viewer.DisplayRectangle.Left; float yOffset = -_viewer.DisplayRectangle.Top; LeadPoint center = new LeadPoint((int)((_center.X + xOffset) * xFactor + 0.5), (int)((_center.Y + yOffset) * yFactor + 0.5)); LeadPoint current = new LeadPoint((int)((_curntMousePoint.X + xOffset) * xFactor + 0.5), (int)((_curntMousePoint.Y + yOffset) * yFactor + 0.5)); int Radius = Length(center, current); e.Graphics.FillEllipse(Brushes.Red, RectFromCenterRadius(center, 2)); e.Graphics.IntersectClip(_viewer.ClientRectangle); if (!_isCircle) { e.Graphics.DrawRectangle(Pens.Yellow, RectFromCenterRadius(center, Radius)); } else { e.Graphics.DrawEllipse(Pens.Yellow, RectFromCenterRadius(center, Radius)); } } } }
void rasterImageViewer1_PostRender(object sender, ImageViewerRenderEventArgs e) { if (!selectedRect.IsEmpty) { LeadRectD rect = rasterImageViewer1.ImageTransform.TransformRect(selectedRect.ToLeadRectD()); e.PaintEventArgs.Graphics.FillRectangle(brush, new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height)); } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs args) { PaintEventArgs e = args.PaintEventArgs; if (_gwireCommand != null) { if (_gwireStarted) { if (_gwirePath != null && _anchorPoints != null) { double xFactor = _viewer.XScaleFactor; double yFactor = _viewer.YScaleFactor; float xOffset = -_viewer.DisplayRectangle.Left; float yOffset = -_viewer.DisplayRectangle.Top; try { if (_gwirePath.Length > 1) { Point[] currentPath = (Point[])_gwirePath.Clone(); for (int idx = 0; idx < currentPath.Length; idx++) { currentPath[idx].X = (int)(xFactor * (currentPath[idx].X + xOffset) + 0.5); currentPath[idx].Y = (int)(yFactor * (currentPath[idx].Y + yOffset) + 0.5); } e.Graphics.DrawLines(Pens.Yellow, currentPath); } if (_gwirePrevPath != null) { if (_gwirePrevPath.Count > 1) { Point[] oldPath = _gwirePrevPath.ToArray(); for (int idx = 0; idx < oldPath.Length; idx++) { oldPath[idx].X = (int)(xFactor * (oldPath[idx].X + xOffset) + 0.5); oldPath[idx].Y = (int)(yFactor * (oldPath[idx].Y + yOffset) + 0.5); } e.Graphics.DrawLines(Pens.Yellow, oldPath); } } for (int i = 0; i < _anchorPoints.Count; i++) { e.Graphics.FillEllipse(Brushes.Yellow, CreateRectangleFromPoint(new Point((int)((_anchorPoints[i].X + xOffset) * xFactor + 0.5), (int)((_anchorPoints[i].Y + yOffset) * yFactor + 0.5)))); } } catch (System.Exception ex) { Messager.ShowError(null, ex); } } } } }
protected override void RenderItemPlaceholder(ImageViewerRenderEventArgs e) { // This method is called while an item is being loaded and give us a chance // to offer a hint to the user // Lets render a Loading ... message on the item var transform = this.ImageViewer.GetItemImageTransform(e.Item); var graphics = e.PaintEventArgs.Graphics; var pt = LeadPointD.Create(0, 0); pt = transform.Transform(pt); graphics.DrawString("Loading...", this.ImageViewer.Font, Brushes.Black, (float)pt.X, (float)pt.Y); }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs e) { if (_firstPointSelected) { double xFactor = _viewer.XScaleFactor; double yFactor = _viewer.YScaleFactor; float xOffset = -_viewer.ImageBounds.Left; float yOffset = -_viewer.ImageBounds.Top; Point[] drawPoints = new Point[_polyPoints.Count]; for (int idx = 0; idx < drawPoints.Length; idx++) { LeadPointD TempPoint = new LeadPointD(_polyPoints[idx].X, _polyPoints[idx].Y); TempPoint = _viewer.ImageTransform.Transform(TempPoint); drawPoints[idx] = new Point((int)TempPoint.X, (int)TempPoint.Y); } LeadPointD lastPointTemp = new LeadPointD(_lastPoint.X, _lastPoint.Y); lastPointTemp = _viewer.ImageTransform.Transform(lastPointTemp); Point lastPoint = new Point((int)lastPointTemp.X, (int)lastPointTemp.Y); LeadPointD currentMousePointTemp = new LeadPointD(_currentMousePoint.X, _currentMousePoint.Y); currentMousePointTemp = _viewer.ImageTransform.Transform(currentMousePointTemp); Point currentMousePoint = new Point((int)currentMousePointTemp.X, (int)currentMousePointTemp.Y); const int controlPointSize = 5; e.PaintEventArgs.Graphics.FillRectangle(Brushes.Red, CreateRectFromPoint(drawPoints[0], controlPointSize)); for (int i = 1; i < drawPoints.Length; i++) { Point prev = drawPoints[i - 1]; Point curnt = drawPoints[i]; e.PaintEventArgs.Graphics.DrawLine(Pens.Yellow, prev, curnt); if (!_drawing) { e.PaintEventArgs.Graphics.DrawLine(Pens.Yellow, drawPoints[0], drawPoints[drawPoints.Length - 1]); } e.PaintEventArgs.Graphics.FillRectangle(Brushes.Red, CreateRectFromPoint(prev, controlPointSize)); e.PaintEventArgs.Graphics.FillRectangle(Brushes.Red, CreateRectFromPoint(curnt, controlPointSize)); } e.PaintEventArgs.Graphics.FillRectangle(Brushes.Red, CreateRectFromPoint(drawPoints[0], controlPointSize)); if (_drawing && drawPoints.Length < 4) { e.PaintEventArgs.Graphics.DrawLine(Pens.Red, lastPoint, currentMousePoint); } } }
void _viewer_Paint(object sender, ImageViewerRenderEventArgs e) { if (_currentSegment.Count >= 2) { e.PaintEventArgs.Graphics.DrawLines(Pens.Yellow, _currentSegment.ToArray()); } foreach (List <Point> pnts in _points) { if (pnts.Count >= 2) { e.PaintEventArgs.Graphics.DrawLines(Pens.Yellow, pnts.ToArray()); } } }
private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { if (_imageViewer.Image == null) { return; } Graphics g = e.PaintEventArgs.Graphics; if (_viewHighlightRecognizedWordsToolStripMenuItem.Checked) { // Highlight all words using (Brush b = new SolidBrush(Color.FromArgb(64, Color.Black))) { using (Pen p = new Pen(Color.FromArgb(64, Color.Black))) { for (int zoneIndex = 0; zoneIndex < _ocrZoneWords.Count; zoneIndex++) { List <OcrWord> zoneWords = _ocrZoneWords[zoneIndex]; for (int wordIndex = 0; wordIndex < zoneWords.Count; wordIndex++) { // Only draw this if it is not the selected word // This will be painted later if (zoneIndex != _selectedZoneIndex || wordIndex != _selectedWordIndex) { HighlightWord(g, zoneIndex, wordIndex, b, p); } } } } } } // If we have a word selected, highlight it if (_selectedZoneIndex != -1 && _selectedWordIndex != -1) { using (Brush b = new SolidBrush(Color.FromArgb(128, Color.Yellow))) { using (Pen p = new Pen(Color.FromArgb(128, Color.Red))) { HighlightWord(g, _selectedZoneIndex, _selectedWordIndex, b, p); } } } }
private void _rasterImageViewer_PostImagePaint(object sender, ImageViewerRenderEventArgs e) { // If this page is recognized, show info if (_ocrPage != null && _ocrPage.IsRecognized) { Graphics g = e.PaintEventArgs.Graphics; string text = "Page is recognized"; SizeF textSize = g.MeasureString(text, _rasterImageViewer.Font); RectangleF textRect = new RectangleF(2, 2, textSize.Width, textSize.Height); using (Brush textBrush = new SolidBrush(Color.FromArgb(128, Color.Black))) { g.FillRectangle(textBrush, textRect); g.DrawString(text, _rasterImageViewer.Font, Brushes.White, textRect.Location); } } }
private void _viewer_Paint(object sender, ImageViewerRenderEventArgs e) { Graphics g = e.PaintEventArgs.Graphics; try { if (_viewer.Image != null && _currentHighlightRect != LeadRect.Empty) { LeadRect imageRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, _currentHighlightRect); Rectangle drawRect = Rectangle.FromLTRB(imageRect.Left, imageRect.Top, imageRect.Right, imageRect.Bottom); g.DrawRectangle(new Pen(Color.Orange), drawRect); g.FillRectangle(new SolidBrush(Color.FromArgb(70, Color.Yellow)), drawRect); } } catch (Exception ex) { Messager.ShowError(this, ex); } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs args) { PaintEventArgs e = args.PaintEventArgs; if (_firstPointSelected) { double xFactor = _viewer.XScaleFactor; double yFactor = _viewer.YScaleFactor; float xOffset = -_viewer.DisplayRectangle.Left; float yOffset = -_viewer.DisplayRectangle.Top; Point[] drawPoints = new Point[_polyPoints.Count]; for (int idx = 0; idx < drawPoints.Length; idx++) { drawPoints[idx] = new Point((int)((_polyPoints[idx].X + xOffset) * xFactor + 0.5), (int)((_polyPoints[idx].Y + yOffset) * yFactor + 0.5)); } Point lastPoint = new Point((int)((_lastPoint.X + xOffset) * xFactor + 0.5), (int)((_lastPoint.Y + yOffset) * yFactor + 0.5)); Point currentMousePoint = new Point((int)((_currentMousePoint.X + xOffset) * xFactor + 0.5), (int)((_currentMousePoint.Y + yOffset) * yFactor + 0.5)); int size = 3; e.Graphics.FillEllipse(Brushes.Green, CreateRectFromPoint(drawPoints[0], size)); for (int i = 1; i < drawPoints.Length; i++) { Point prev = drawPoints[i - 1]; Point curnt = drawPoints[i]; e.Graphics.DrawLine(Pens.Yellow, prev, curnt); if (!_drawing) { e.Graphics.DrawLine(Pens.Yellow, drawPoints[0], drawPoints[drawPoints.Length - 1]); } e.Graphics.FillEllipse(Brushes.Green, CreateRectFromPoint(prev, size)); e.Graphics.FillEllipse(Brushes.Green, CreateRectFromPoint(curnt, size)); } if (_drawing && drawPoints.Length < 4) { e.Graphics.DrawLine(Pens.Green, lastPoint, currentMousePoint); } } }
private static void RenderContainer(ImageViewerRenderEventArgs e, AnnRenderingEngine renderingEngine, AnnContainer container, bool runMode) { // Attach to the current container and graphics var context = e.PaintEventArgs.Graphics; var clipRectangle = e.PaintEventArgs.ClipRectangle; // Render the annotations renderingEngine.Attach(container, (Graphics)context); try { // Convert the clip rectangle to annotation coordinates var annClipRect = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height); annClipRect = container.Mapper.RectToContainerCoordinates(annClipRect); renderingEngine.Render(annClipRect, runMode); } finally { renderingEngine.Detach(); } }
private void RenderContainer(ImageViewerRenderEventArgs e, AnnDrawRenderingEngine engine, AnnContainer container) { object surface = e.SurfaceContext; if (surface == null) { return; } // Attach to the current container and graphics. engine.Attach(container, surface); try { // Render the annotations engine.Render(LeadRectD.Empty, false); } finally { engine.Detach(); } }
private static void RenderContainer(ImageViewerRenderEventArgs e, AnnRenderingEngine renderingEngine, AnnContainer container, bool runMode) { object surface = e.SurfaceContext; if (surface == null) { return; } // Attach to the current container and context renderingEngine.Attach(container, surface); try { // Render the annotations renderingEngine.Render(LeadRectD.Empty, runMode); } finally { renderingEngine.Detach(); } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs e) { Graphics g = e.PaintEventArgs.Graphics; try { if (_viewer.Image != null && _ocrPage.Zones.Count > 0) { for (int i = 0; i < _ocrPage.Zones.Count; i++) { LeadRect bounds = _ocrPage.Zones[i].Bounds; LeadRect rect = LeadRect.FromLTRB(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); rect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, rect); using (Pen pen = new Pen(Color.Red, 2)) { g.DrawRectangle(pen, Leadtools.Demos.Converters.ConvertRect(rect)); } } } } catch (Exception) { } }
private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { // Do we have a rendering engine? var renderingEngine = this.RenderingEngine as Leadtools.Annotations.Rendering.AnnWinFormsRenderingEngine; if (renderingEngine == null) { return; } bool runMode = false; if (_automationObject != null && _automationObject.Manager != null) { runMode = (_automationObject.Manager.UserMode == AnnUserMode.Run); } var context = e.PaintEventArgs.Graphics; var saveSmoothingMode = context.SmoothingMode; try { // Set the anti alias mode if (this.AutomationAntiAlias) { if (context.SmoothingMode != SmoothingMode.AntiAlias) { context.SmoothingMode = SmoothingMode.AntiAlias; } } else { if (context.SmoothingMode != SmoothingMode.Default) { context.SmoothingMode = SmoothingMode.Default; } } // Do we have multiple containers? if (_getContainersCallback != null) { // Yes, get the container for this item var containers = _getContainersCallback(); var clipRect = LeadRectD.Create( e.PaintEventArgs.ClipRectangle.X, e.PaintEventArgs.ClipRectangle.Y, e.PaintEventArgs.ClipRectangle.Width, e.PaintEventArgs.ClipRectangle.Height); if (containers != null) { switch (this.MultiContainerMode) { case AutomationControlMultiContainerMode.MultiPage: // Each container belong to an item for (var index = 0; index < containers.Count; index++) { if (index < _imageViewer.Items.Count) { var itemBounds = _imageViewer.GetItemBounds(_imageViewer.Items[index], ImageViewerItemPart.Item); if (!itemBounds.IsEmpty) { var container = containers[index]; var item = _imageViewer.Items[index]; var containerBounds = _automationObject.GetContainerInvalidRect(container, true); var intersects = !containerBounds.IsEmpty && containerBounds.IntersectsWith(clipRect); if (intersects || !_imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Item, true).IsEmpty) { RenderContainer(e, renderingEngine, container, runMode); } } } } break; case AutomationControlMultiContainerMode.SinglePage: default: // All containers belong to the active item ImageViewerItem activeItem = _imageViewer.ActiveItem; if (activeItem != null && !_imageViewer.GetItemViewBounds(activeItem, ImageViewerItemPart.Item, true).IsEmpty) { for (var index = 0; index < containers.Count; index++) { var itemBounds = _imageViewer.GetItemBounds(activeItem, ImageViewerItemPart.Item); if (!itemBounds.IsEmpty) { var container = containers[index]; var containerBounds = _automationObject.GetContainerInvalidRect(container, true); var intersects = !containerBounds.IsEmpty && containerBounds.IntersectsWith(clipRect); if (intersects) { RenderContainer(e, renderingEngine, container, runMode); } } } } break; } } } else { // Using single-containers, just render the one the user set var container = this._container; if (container != null) { RenderContainer(e, renderingEngine, container, runMode); } } } finally { if (context.SmoothingMode != saveSmoothingMode) { context.SmoothingMode = saveSmoothingMode; } } }
private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e) { // Do we have a rendering engine? var renderingEngine = this.RenderingEngine as AnnDrawRenderingEngine; if (renderingEngine == null) { return; } bool runMode = false; if (_automationObject != null && _automationObject.Manager != null) { runMode = (_automationObject.Manager.UserMode == AnnUserMode.Run); } try { // Do we have multiple containers? if (_getContainersCallback != null) { // Yes, get the container for this item var containers = _getContainersCallback(); if (containers != null) { switch (this.MultiContainerMode) { case AutomationControlMultiContainerMode.MultiPage: // Each container belong to an item for (var index = 0; index < containers.Count; index++) { if (index < _imageViewer.Items.Count) { var itemBounds = _imageViewer.GetItemBounds(_imageViewer.Items[index], ImageViewerItemPart.Item); if (!itemBounds.IsEmpty) { var container = containers[index]; var item = _imageViewer.Items[index]; var containerBounds = _automationObject.GetContainerInvalidRect(container, true); if (!_imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Item, true).IsEmpty) { RenderContainer(e, renderingEngine, container, runMode); } } } } break; case AutomationControlMultiContainerMode.SinglePage: default: // All containers belong to the active item ImageViewerItem activeItem = _imageViewer.ActiveItem; if (activeItem != null && !_imageViewer.GetItemViewBounds(activeItem, ImageViewerItemPart.Item, true).IsEmpty) { for (var index = 0; index < containers.Count; index++) { var itemBounds = _imageViewer.GetItemBounds(activeItem, ImageViewerItemPart.Item); if (!itemBounds.IsEmpty) { var container = containers[index]; RenderContainer(e, renderingEngine, container, runMode); } } } break; } } } else { // Using single-containers, just render the one the user set var container = this._container; if (container != null) { RenderContainer(e, renderingEngine, container, runMode); } } } finally { } }
private void _rasterImageViewer_PostImagePaint(object sender, ImageViewerRenderEventArgs e) { RasterImage image = _rasterImageViewer.Image; if (image != null && !_disableExtraDrawing) { if (ShowBarcodes) { using (StringFormat sf = new StringFormat()) using (Brush normalBrush = new SolidBrush(Color.FromArgb(200, Color.DarkGreen))) using (Pen normalPen = new Pen(Color.FromArgb(180, Color.DarkGreen), 4)) using (Brush selectedBrush = new SolidBrush(Color.FromArgb(200, Color.Blue))) using (Pen selectedPen = new Pen(Color.FromArgb(180, Color.Blue), 4)) { sf.FormatFlags = StringFormatFlags.NoWrap; // Draw the barcodes for this page int index = 0; PageBarcodes pageBarcodes = _documentBarcodes.Pages[image.Page - 1]; foreach (BarcodeData data in pageBarcodes.Barcodes) { if (index == pageBarcodes.SelectedIndex) { DrawBarcodeData(e.PaintEventArgs.Graphics, image, data, sf, selectedBrush, selectedPen); } else { DrawBarcodeData(e.PaintEventArgs.Graphics, image, data, sf, normalBrush, normalPen); } index++; } } } if (_viewerRegion && _rasterImageViewer.Image.Page == _viewerRegionPage) { // Draw an alpha brush around the image region if (!_rasterImageViewer.Image.HasRegion) { _rasterImageViewer.Image.SetRegion(null, RegionG, RasterRegionCombineMode.Set); } LeadRect regionBounds = RegionG.GetBounds();// _rasterImageViewer.Image.GetRegionBounds(null); LeadRectD regionRect = new LeadRectD(regionBounds.X, regionBounds.Y, regionBounds.Width, regionBounds.Height); regionRect = _rasterImageViewer.ImageTransform.TransformRect(regionRect); regionRect.Inflate(1, 1); LeadRectD imageRect = new LeadRectD(0, 0, image.ImageWidth, image.ImageHeight); imageRect = _rasterImageViewer.ImageTransform.TransformRect(imageRect); imageRect.Inflate(1, 1); using (Region region = new Region(new Rectangle((int)imageRect.X, (int)imageRect.Y, (int)imageRect.Width, (int)imageRect.Height))) { region.Exclude(new Rectangle((int)regionRect.X, (int)regionRect.Y, (int)regionRect.Width, (int)regionRect.Height)); using (Brush brush = new HatchBrush(HatchStyle.SmallConfetti, Color.Black, Color.FromArgb(64, Color.Black))) { e.PaintEventArgs.Graphics.FillRegion(brush, region); } } e.PaintEventArgs.Graphics.DrawRectangle(Pens.Black, (int)regionRect.X, (int)regionRect.Y, (int)regionRect.Width, (int)regionRect.Height); e.PaintEventArgs.Graphics.DrawRectangle(Pens.Black, (int)imageRect.X, (int)imageRect.Y, (int)imageRect.Width, (int)imageRect.Height); } } }
private void _viewer_Paint(object sender, ImageViewerRenderEventArgs e) { Graphics g = e.PaintEventArgs.Graphics; try { if (_viewer.Image != null && _currentHighlightRect != LeadRect.Empty) { LeadRect imageRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, _currentHighlightRect); Rectangle drawRect = Rectangle.FromLTRB(imageRect.Left, imageRect.Top, imageRect.Right, imageRect.Bottom); g.DrawRectangle(new Pen(Color.Orange), drawRect); g.FillRectangle(new SolidBrush(Color.FromArgb(70, Color.Yellow)), drawRect); } } catch (Exception ex) { Messager.ShowError(this, ex); } }
void _viewer_PostRender(object sender, ImageViewerRenderEventArgs e) { if (_firstPointSelected) { double xFactor = _viewer.XScaleFactor; double yFactor = _viewer.YScaleFactor; float xOffset = -_viewer.ImageBounds.Left; float yOffset = -_viewer.ImageBounds.Top; Point[] drawPoints = new Point[_unWarpPoints.Count]; for (int idx = 0; idx < drawPoints.Length; idx++) { LeadPointD TempPoint = new LeadPointD(_unWarpPoints[idx].X, _unWarpPoints[idx].Y); TempPoint = _viewer.ImageTransform.Transform(TempPoint); drawPoints[idx] = new Point((int)TempPoint.X, (int)TempPoint.Y); } /************************************************************************/ const int controlPointSize = 5; for (int i = 0; i < drawPoints.Length; i++) { e.PaintEventArgs.Graphics.FillRectangle(Brushes.Red, CreateRectFromPoint(drawPoints[i], controlPointSize)); } if (drawPoints.Length >= 4) { _drawing = false; Point[] line = new Point[2]; line[0] = drawPoints[0]; line[1] = drawPoints[3]; e.PaintEventArgs.Graphics.DrawLine(Pens.Yellow, line[0], line[1]); line[0] = drawPoints[1]; line[1] = drawPoints[2]; e.PaintEventArgs.Graphics.DrawLine(Pens.Yellow, line[0], line[1]); if (_upperCurvePath == null || _upperCurvePath.Length == 0) { return; } Point[] curvePoints = new Point[_upperCurvePath.Length]; for (int j = 0; j < _upperCurvePath.Length; j++) { LeadPointD TempPoint = new LeadPointD(_upperCurvePath[j].X, _upperCurvePath[j].Y); TempPoint = _viewer.ImageTransform.Transform(TempPoint); curvePoints[j] = new Point((int)TempPoint.X, (int)TempPoint.Y); } e.PaintEventArgs.Graphics.DrawCurve(Pens.Yellow, curvePoints); if (_lowerCurvePath == null || _lowerCurvePath.Length == 0) { return; } curvePoints = new Point[_lowerCurvePath.Length]; for (int j = 0; j < _lowerCurvePath.Length; j++) { LeadPointD TempPoint = new LeadPointD(_lowerCurvePath[j].X, _lowerCurvePath[j].Y); TempPoint = _viewer.ImageTransform.Transform(TempPoint); curvePoints[j] = new Point((int)TempPoint.X, (int)TempPoint.Y); } e.PaintEventArgs.Graphics.DrawCurve(Pens.Yellow, curvePoints); } else { for (int i = 1; i < drawPoints.Length; i++) { Point prev = drawPoints[i - 1]; Point curnt = drawPoints[i]; e.PaintEventArgs.Graphics.DrawLine(Pens.Yellow, prev, curnt); if (!_drawing) { e.PaintEventArgs.Graphics.DrawLine(Pens.Yellow, drawPoints[0], drawPoints[drawPoints.Length - 1]); } } } } }
protected override void OnPostRender(ImageViewerRenderEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } var engine = _engine as AnnWinFormsRenderingEngine; var context = e.PaintEventArgs.Graphics; var saveSmoothingMode = context.SmoothingMode; bool runMode = false; if (_automationObject != null && _automationObject.Manager != null) { runMode = (_automationObject.Manager.UserMode == AnnUserMode.Run); } try { // Set the anti alias mode if (this.AutomationAntiAlias) { if (context.SmoothingMode != SmoothingMode.AntiAlias) { context.SmoothingMode = SmoothingMode.AntiAlias; } } else { if (context.SmoothingMode != SmoothingMode.Default) { context.SmoothingMode = SmoothingMode.Default; } } // Render all containers if (_getContainersCallback != null) { // Using multi-containers var containers = _getContainersCallback(); foreach (var container in containers) { RenderContainer(e.PaintEventArgs, engine, container, runMode); } } else { // Using single-containers, just render the active RenderContainer(e.PaintEventArgs, engine, _container, runMode); } } finally { if (context.SmoothingMode != saveSmoothingMode) { context.SmoothingMode = saveSmoothingMode; } } base.OnPostRender(e); }