public static LeadRectD GetBoundingRect(LeadPointD[] points) { double xmin = points[0].X; double ymin = points[0].Y; double xmax = xmin; double ymax = ymin; for (int i = 1; i < points.Length; i++) { if (points[i].X < xmin) { xmin = points[i].X; } if (points[i].X > xmax) { xmax = points[i].X; } if (points[i].Y < ymin) { ymin = points[i].Y; } if (points[i].Y > ymax) { ymax = points[i].Y; } } return(LeadRectD.FromLTRB(xmin, ymin, xmax, ymax)); }
private void AdjustFusionImage_Edit(object sender, AnnRectangleObject fusionEditRect) { int subCellIndex = _cell.ActiveSubCell; int index = _cmbFusedIndex.SelectedIndex; MedicalViewerFusion fusion = _cell.SubCells[subCellIndex].Fusion[index]; AnnContainer _Container = GetContainer(_cell, fusionEditRect); fusion.Rotation = (float)fusionEditRect.Angle; LeadPointD[] pt = new LeadPointD[1]; LeadRectD rect = _Container.Mapper.RectFromContainerCoordinates(fusionEditRect.Rect, AnnFixedStateOperations.None); Rectangle displayRect = _cell.GetDisplayedImageRectangle(); rect.Offset(-displayRect.Left, -displayRect.Top); pt[0].X = (float)(rect.X + rect.Width / 2); pt[0].Y = (float)(rect.Y + rect.Height / 2); LeadPointD point = LeadPointD.Create(pt[0].X, pt[0].Y); _cell.AutomationContainer.Mapper.Transform.TransformPoints(pt); float normalizedXPosition = (float)(((float)point.X - (float)displayRect.Width / 2) / fusion.FusedImage.Width * 100 / _cell.GetScale(subCellIndex)); float normalizedYPosition = (float)(((float)point.Y - (float)displayRect.Height / 2) / fusion.FusedImage.Height * 100 / _cell.GetScale(subCellIndex)); float scaleX = (float)((rect.Width / fusion.FusedImage.Width) * 100 / _cell.GetScale(subCellIndex)); float scaleY = (float)((rect.Height / fusion.FusedImage.Height) * 100 / _cell.GetScale(subCellIndex)); if (scaleX == 0) { scaleX = 0.1F; } if (scaleY == 0) { scaleY = 0.1F; } RectangleF rectangle = new RectangleF(normalizedXPosition, normalizedYPosition, Math.Abs(scaleX), Math.Abs(scaleY)); fusion.DisplayRectangle = rectangle; UpdateFusionUI(index); CellData cellData = (CellData)_cell.Tag; if (cellData.SyncCellFusion) { UpdateCellFusions(fusion, subCellIndex, index); } _cell.Invalidate(); }
private bool IsValidY(int y) { LeadRectD itemBounds = ImageViewer.GetItemBounds(ImageViewer.ActiveItem, ImageViewerItemPart.Item); itemBounds = ImageViewer.ConvertRect(null, ImageViewerCoordinateType.Item, ImageViewerCoordinateType.Image, itemBounds); return(y >= 0.0 && y <= itemBounds.Size.Height); }
void _rasterImageList_PostRender(object sender, Leadtools.Controls.ImageViewerRenderEventArgs e) { for (int i = 0; i < _rasterImageList.Items.Count; i++) { ImageViewerItem item = _rasterImageList.Items[i]; LeadRectD itemLeadRect = _rasterImageList.GetItemBounds(item, ImageViewerItemPart.Item); Rectangle itemRect = new Rectangle((int)itemLeadRect.X, (int)itemLeadRect.Y, (int)itemLeadRect.Width, (int)itemLeadRect.Height); LeadSize itemImageSize = _rasterImageList.GetItemImageSize(item, false); LeadRect imageRect = new LeadRect( itemRect.Left + (itemRect.Width - itemImageSize.Width) / 2, itemRect.Top + (itemRect.Height - itemImageSize.Height) / 2, itemImageSize.Width, itemImageSize.Height); itemLeadRect = ImageViewer.GetDestinationRectangle(item.Image.ImageWidth, item.Image.ImageHeight, imageRect, ControlSizeMode.None, ControlAlignment.Near, ControlAlignment.Near).ToLeadRectD(); var destRect = LeadRectD.Create(itemLeadRect.X, itemLeadRect.Y, itemLeadRect.Width * 720.0 / 96.0, itemLeadRect.Height * 720.0 / 96.0); destRect.X = 0.0; destRect.Y = 0.0; //Get the graphic object from the item's image to draw (burn) annotations on it. Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer GdiPlusGraphicsContainer = new RasterImageGdiPlusGraphicsContainer(item.Image); Graphics g = GdiPlusGraphicsContainer.Graphics; // Use anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Now draw the annotation s on this rectangle if (_automationManager != null && _automation.Containers.Count > 0 && _automation.Containers.Count > i) { AnnContainer container = _automation.Containers[i]; //Clear the old painting g.Clear(Color.White); //Burn the current annotations to the image list item if (container != null) { AnnWinFormsRenderingEngine engine = new AnnWinFormsRenderingEngine(); engine.Resources = _automationManager.Resources; // Save its visible state and set it to true (it is false if viewer is in single mode) bool containerIsVisible = container.IsVisible; container.IsVisible = true; engine.Attach(container, g); engine.BurnToRectWithDpi(destRect, 96, 96, 96, 96); engine.Detach(); if (container.IsVisible != containerIsVisible) { container.IsVisible = containerIsVisible; } } } } }
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); } } } }
internal void AddSelectedObject(AnnObjectTreeNode node) { node.IsSelected = true; node.Invalidate(); SelectedItems.Add(node); AnnObjectCollection annObjects = new AnnObjectCollection(); foreach (AnnObjectTreeNode item in SelectedItems) { annObjects.Add(item.AnnObject); } if (_imageViewer != null && _automation != null) { var invalidRect = LeadRectD.Empty; foreach (AnnObject annObject in annObjects) { if (annObject != null) { invalidRect = LeadRectD.UnionRects(invalidRect, _automation.GetObjectInvalidateRect(annObject)); } } _automation.ActiveContainer = ((PageTreeNode)node.TreeParentNode).AnnContainer; _automation.SelectObjects(annObjects); _imageViewer.EnsureBoundsVisible(invalidRect); } }
private bool IsValidX(int x) { LeadRectD itemBounds = ImageViewer.GetItemBounds(ImageViewer.ActiveItem, ImageViewerItemPart.Item); itemBounds = ImageViewer.ConvertRect(null, ImageViewerCoordinateType.Item, ImageViewerCoordinateType.Image, itemBounds); return(x >= 0.0 && x <= itemBounds.Size.Width); }
// Rendering public virtual void AutomationInvalidate(LeadRectD rc) { // Invalidate the viewer if (_imageViewer != null) { _imageViewer.InvalidateImageSurface(rc); } }
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)); } }
static AnnHiliteObject CreateHilite(LeadRectD rect) { AnnHiliteObject annHiliteObject = new AnnHiliteObject(); annHiliteObject.Rect = rect; return(annHiliteObject); }
private LeadRectD BoundsToAnnotations(AnnObject annObject, RectangleF rect) { // Convert a rectangle from logical (top-left) to annotation object coordinates LeadRectD rc = LeadRectD.Create(rect.Left + System.Convert.ToDouble(rect.Width < 0) * rect.Width, rect.Top + System.Convert.ToDouble(rect.Height < 0) * rect.Height, Math.Abs(rect.Width), Math.Abs(rect.Height)); rc = _filledFormViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, rc); rc = automation.Container.Mapper.RectToContainerCoordinates(rc); return(rc); }
private LeadRectD BoundsToAnnotations(AnnRectangleObject rectObject, LeadRect rect, AnnContainer container) { // Convert a rectangle from logical (top-left) to annotation object coordinates LeadRectD rc = rect.ToLeadRectD(); rc = _rasterImageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, rc); rc = container.Mapper.RectToContainerCoordinates(rc); return(rc); }
public LeadRectD ToImage(LeadRectD value) { LeadRectD result = LeadRectD.FromLTRB( value.Left * XRatio, value.Top * YRatio, value.Right * XRatio, value.Bottom * YRatio);//, //value.Unit); return(result); }
protected override LeadRectD GetBoundingRectangle() { LeadRectD rc = base.GetBoundingRectangle(); if (!_cobbAngleData.IntersectionPoint.IsEmpty) { rc = LeadRectD.Union(rc, _cobbAngleData.IntersectionPoint); } return(rc); }
public LeadRectD FromImage(LeadRectD value) { LeadRectD result = LeadRectD.FromLTRB( value.Left / XRatio, value.Top / YRatio, value.Right / XRatio, value.Bottom / YRatio);//, // value.Unit); return(result); }
void CreateDefaultLayers() { string[] layers = new string[] { "Red", "Green", "Blue" }; LeadRectD rect = new LeadRectD(LeadPointD.Create(860, 700), LeadPointD.Create(5200, 1850)); foreach (string layer in layers) { CreateRectangle(rect, AnnSolidColorBrush.Create(layer), CreateLayer(string.Format("{0} Layer", layer))); rect.Offset(360, 360); } }
// Called to invalidate an area on the viewer public void AutomationInvalidate(LeadRectD rc) { if (rc.IsEmpty) { Invalidate(); } else { Rectangle rect = new Rectangle((int)(rc.Left + .5), (int)(rc.Top + .5), (int)(rc.Width + .5), (int)(rc.Height + .5)); Invalidate(rect); } }
private void AddHighlight(Rectangle highlightBounds) { AnnHiliteObject annotationField = new AnnHiliteObject(); annotationField.HiliteColor = "Yellow"; automation.Container.Children.Add(annotationField); //Now we can calculate the object bounds correctly RectangleF rc = RectangleF.FromLTRB(highlightBounds.Left, highlightBounds.Top, highlightBounds.Right, highlightBounds.Bottom); LeadRectD rect = BoundsToAnnotations(annotationField, rc); annotationField.Rect = rect; }
// Rendering public virtual void AutomationInvalidate(LeadRectD rc) { if (rc.IsEmpty) { Invalidate(); } else { var rect = new Rectangle((int)(rc.X + .5), (int)(rc.Y + .5), (int)(rc.Width + .5), (int)(rc.Height + .5)); Invalidate(rect); } }
AnnRectangleObject CreateRectangle(LeadRectD rect, AnnBrush brush, AnnLayer layer) { AnnRectangleObject annRectObject = new AnnRectangleObject(); annRectObject.Rect = rect; annRectObject.Fill = brush; annRectObject.Stroke.Stroke = AnnSolidColorBrush.Create("yellow"); _automation.Container.Children.Add(annRectObject); layer.Children.Add(annRectObject); return(annRectObject); }
protected override LeadRectD GetBoundingRectangle() { LeadRectD rc = base.GetBoundingRectangle(); double radius = _centerPointRadius.Value; if (!(double.IsInfinity(radius) || (double.IsInfinity(radius))) && !rc.IsEmpty) { rc.Inflate(radius, radius); } return(rc); }
public static LeadPointD[] GetCornerPoints(LeadRectD rect) { bool isEmpty = rect.IsEmpty; LeadPointD[] corners = { !isEmpty ? LeadPointD.Create(rect.Left, rect.Top) : LeadPointD.Create(0, 0), !isEmpty ? LeadPointD.Create(rect.Right, rect.Top) : LeadPointD.Create(0, 0), !isEmpty ? LeadPointD.Create(rect.Right, rect.Bottom) : LeadPointD.Create(0, 0), !isEmpty ? LeadPointD.Create(rect.Left, rect.Bottom) : LeadPointD.Create(0, 0), }; return(corners); }
private void DrawBarcodeData(Graphics g, RasterImage image, BarcodeData data, StringFormat sf, Brush brush, Pen pen) { LeadRect rect = data.Bounds; LeadRectD rc = new LeadRectD(rect.X, rect.Y, rect.Width, rect.Height); string line = BarcodeEngine.GetSymbologyFriendlyName(data.Symbology); if (FourPoints && data.Symbology != BarcodeSymbology.Aztec && data.Symbology != BarcodeSymbology.Maxi && data.Symbology != BarcodeSymbology.MicroQR) { LeadPointD[] pointsL = new LeadPointD[4]; Point[] points = new Point[4]; pointsL[0].X = ((int)rc.Left & 0xffff); pointsL[0].Y = ((int)rc.Left >> 16); pointsL[1].X = ((int)rc.Top & 0xffff); pointsL[1].Y = ((int)rc.Top >> 16); pointsL[2].X = ((int)rc.Width & 0xffff); pointsL[2].Y = ((int)rc.Width >> 16); pointsL[3].X = ((int)rc.Height & 0xffff); pointsL[3].Y = ((int)rc.Height >> 16); _rasterImageViewer.ImageTransform.TransformPoints(pointsL); for (int i = 0; i < 4; i++) { points[i].X = (int)pointsL[i].X; points[i].Y = (int)pointsL[i].Y; } g.DrawPolygon(pen, points); SizeF size = g.MeasureString(line, Font, points[2].X - points[0].X, sf); rc.Width = (int)size.Width + 1; rc.Height = (int)size.Height + 1; g.FillRectangle(brush, points[0].X, points[0].Y, (int)rc.Width, (int)rc.Height); g.DrawString(line, Font, Brushes.White, new RectangleF(points[0].X, points[0].Y, (int)rc.Width, (int)rc.Height), sf); } else { rc = _rasterImageViewer.ImageTransform.TransformRect(rc); rc.Inflate(3, 3); if (rc.Width < 10 || rc.Height < 10) { return; } g.DrawRectangle(pen, (int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height); SizeF size = g.MeasureString(line, Font, (int)rc.Width, sf); rc.Width = (int)size.Width + 1; rc.Height = (int)size.Height + 1; g.FillRectangle(brush, (int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height); g.DrawString(line, Font, Brushes.White, new RectangleF((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), sf); } }
private void SetViewerZoomPercentage(double percentage) { // Normalize the percentage based on min/max value allowed percentage = Math.Max(_minimumViewerScalePercentage, Math.Min(_maximumViewerScalePercentage, percentage)); if (Math.Abs(_rasterImageViewer.ScaleFactor * 100.0 - percentage) > 0.01) { // Save the current center location in the viewer, we will use it later to // re-center the viewer LeadRectD LeadPhysicalViewRectangle = _rasterImageViewer.GetItemViewBounds(_rasterImageViewer.ActiveItem, ImageViewerItemPart.Image, true); LeadRectD LeadLogicalViewRectangle = _rasterImageViewer.GetItemBounds(_rasterImageViewer.ActiveItem, ImageViewerItemPart.Image); Rectangle PhysicalViewRectangle = new Rectangle((int)LeadPhysicalViewRectangle.Left, (int)LeadPhysicalViewRectangle.Top, (int)LeadPhysicalViewRectangle.Width, (int)LeadPhysicalViewRectangle.Height); Rectangle LogicalViewRectangle = new Rectangle((int)LeadLogicalViewRectangle.Left, (int)LeadLogicalViewRectangle.Top, (int)LeadLogicalViewRectangle.Width, (int)LeadLogicalViewRectangle.Height); Rectangle rc = Rectangle.Intersect(PhysicalViewRectangle, LogicalViewRectangle); PointF center = new PointF(rc.Left + rc.Width / 2, rc.Top + rc.Right / 2); LeadMatrix LeadM = _rasterImageViewer.ImageTransform; Matrix M = new Matrix((float)LeadM.M11, (float)LeadM.M12, (float)LeadM.M21, (float)LeadM.M22, (float)LeadM.OffsetX, (float)LeadM.OffsetY); Transformer trans = new Transformer(M); center = trans.PointToLogical(center); _rasterImageViewer.BeginUpdate(); // Switch to normal size mode if we are not in it if (_rasterImageViewer.SizeMode != ControlSizeMode.ActualSize) { _rasterImageViewer.Zoom(ControlSizeMode.ActualSize, 1, _rasterImageViewer.DefaultZoomOrigin); } // Zoom _rasterImageViewer.Zoom(ControlSizeMode.None, percentage / 100.0, _rasterImageViewer.DefaultZoomOrigin); // Go back to original center point LeadM = _rasterImageViewer.ImageTransform; M = new Matrix((float)LeadM.M11, (float)LeadM.M12, (float)LeadM.M21, (float)LeadM.M22, (float)LeadM.OffsetX, (float)LeadM.OffsetY); trans.Transform = M; center = trans.PointToPhysical(center); _rasterImageViewer.CenterAtPoint(LeadPoint.Create((int)center.X, (int)center.Y)); _rasterImageViewer.EndUpdate(); _rasterImageViewer_TransformChanged(_rasterImageViewer, EventArgs.Empty); UpdateUIState(); } }
public void UpdateAnimateRegions(bool animateRegions) { LeadRectD rc = _viewer.GetItemBounds(_viewer.ActiveItem, ImageViewerItemPart.Floater); if (animateRegions) { _viewer.ImageRegionRenderMode = ControlRegionRenderMode.Animated; } else { _viewer.ImageRegionRenderMode = ControlRegionRenderMode.Fixed; } _viewer.FloaterRegionRenderMode = _viewer.ImageRegionRenderMode; }
private void ApplyEncryptDecrypt(ScrambleCommandFlags flags, LeadRectD bounds, int key) { LeadRect boundsInImage = _image.RectangleToImage(RasterViewPerspective.TopLeft, bounds.ToLeadRect()); LeadRect imageRect = LeadRect.Create(0, 0, _image.ImageWidth, _image.ImageHeight); flags |= ScrambleCommandFlags.Intersect; ScrambleCommand scrambleCommand = new ScrambleCommand(boundsInImage, key, flags); if (imageRect.Contains(boundsInImage)) { scrambleCommand.Run(_image); } }
private LeadRect BoundsFromAnnotations(AnnRectangleObject rectObject, AnnContainer container) { // Convert a rectangle from annotation object to logical coordinates (top-left) LeadRectD temp = container.Mapper.RectFromContainerCoordinates(rectObject.Rect, AnnFixedStateOperations.None); if (temp.IsEmpty) { return(LeadRect.Empty); } temp = _rasterImageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, temp); LeadRect rect = temp.ToLeadRect(); return(rect); }
private void ApplyEncryptDecrypt(ScrambleCommandFlags flags, LeadRectD bounds, int key) { LeadRect rect = bounds.ToLeadRect(); LeadRect imageRect = LeadRect.Create(0, 0, _image.ImageWidth, _image.ImageHeight); flags |= ScrambleCommandFlags.Intersect; ScrambleCommand scrambleCommand = new ScrambleCommand(rect, key, flags); if (imageRect.Contains(rect)) { scrambleCommand.Run(_image); } }
private void HighlightWord(Graphics g, int zoneIndex, int wordIndex, Brush b, Pen p) { OcrWord word = _ocrZoneWords[zoneIndex][wordIndex]; // Get the word bounding rectangle and convert to physical so we can draw it on the viewer surface LeadRect rc = LeadRectD.FromLTRB(word.Bounds.Left, word.Bounds.Top, word.Bounds.Right, word.Bounds.Bottom).ToLeadRect(); rc = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, rc); // Make the rectangle a little bit bigger for visibility purposes rc.Inflate(_wordEdge, _wordEdge); g.FillRectangle(b, Leadtools.Demos.Converters.ConvertRect(rc)); g.DrawRectangle(p, rc.X, rc.Y, rc.Width - 1, rc.Height - 1); }
// Rendering public virtual void AutomationInvalidate(LeadRectD rc) { // Invalidate the viewer if (_imageViewer != null) { if (rc.IsEmpty) { _imageViewer.Invalidate(); } else { var rect = new Rectangle((int)(rc.X + .5), (int)(rc.Y + .5), (int)(rc.Width + .5), (int)(rc.Height + .5)); _imageViewer.Invalidate(rect); } } }