public bool OnMouseUp(MouseEventArgs e) { if (selectionRectangle.Width > 0 && selectionRectangle.Height > 0) { Bitmap src = (Bitmap)mainScene.GetRootImage(); Bitmap target = new Bitmap(selectionRectangle.Width, selectionRectangle.Height); using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), selectionRectangle, GraphicsUnit.Pixel); g.Save(); } Rectangle targetImageRect = new Rectangle(new Point(0, 0), selectionRectangle.Size); for (int y = 0; y < target.Height; y++) { for (int x = 0; x < target.Width; x++) { if (!IsInsideEllipse(targetImageRect, new Point(x, y))) { target.SetPixel(x, y, Color.Transparent); } } } int yStart = selectionRectangle.Location.Y; int yEnd = selectionRectangle.Location.Y + selectionRectangle.Height; int xStart = selectionRectangle.Location.X; int xEnd = selectionRectangle.Location.X + selectionRectangle.Width; if (yStart < 0) { yStart = 0; } if (xStart < 0) { xStart = 0; } if (yEnd > src.Height) { yEnd = src.Height; } if (xEnd > src.Width) { xEnd = src.Width; } /*for (int y = yStart; y < yEnd; y++) * for (int x = xStart; x < xEnd; x++) * if (IsInsideEllipse(selectionRectangle, new Point(x, y))) * src.SetPixel(x, y, Color.White);*/ Point p = new Point(selectionRectangle.Left, selectionRectangle.Top); Data.Segment segm = new Data.Segment(target, p); segm.selectionStrategy = this; mainScene.AddSegment(segm); image = segm.image; segmentIndex = mainScene.GetSegmentCount() - 1; } return(true); }
public bool OnMouseUp(MouseEventArgs e) { if (selectionRectangle.Width > 0 && selectionRectangle.Height > 0) { Bitmap src = (Bitmap)mainScene.GetRootImage(); Bitmap target = new Bitmap(selectionRectangle.Width, selectionRectangle.Height); using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), selectionRectangle, GraphicsUnit.Pixel); g.Save(); } /*using (Graphics g = Graphics.FromImage(src)) * { * g.FillRectangle(Brushes.White, selectionRectangle); * g.Save(); * }*/ Point p = new Point(selectionRectangle.Left, selectionRectangle.Top); Data.Segment segm = new Data.Segment(target, p); segm.selectionStrategy = this; mainScene.AddSegment(segm); segmentIndex = mainScene.GetSegmentCount() - 1; } return(true); }
private void CutElement() { Bitmap src = (Bitmap)mainScene.GetRootImage(); int leftX = src.Width; int rightX = 0; int topY = src.Height; int bottomY = 0; foreach (Point po in points) { if (po.X < leftX) { leftX = po.X; } if (po.X > rightX) { rightX = po.X; } if (po.Y < topY) { topY = po.Y; } if (po.Y > bottomY) { bottomY = po.Y; } } Rectangle selectionRectangle = new Rectangle(leftX, topY, rightX - leftX, bottomY - topY); Bitmap target = new Bitmap(selectionRectangle.Width, selectionRectangle.Height); using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), selectionRectangle, GraphicsUnit.Pixel); g.Save(); } newPoints = new Point[points.Count]; for (int i = 0; i < points.Count; i++) { newPoints[i] = new Point(points[i].X - selectionRectangle.Location.X, points[i].Y - selectionRectangle.Location.Y); } for (int y = 0; y < target.Height; y++) { for (int x = 0; x < target.Width; x++) { if (!IsInPolygon(newPoints, new Point(x, y))) { target.SetPixel(x, y, Color.Transparent); } } } int yStart = selectionRectangle.Location.Y; int yEnd = selectionRectangle.Location.Y + selectionRectangle.Height; int xStart = selectionRectangle.Location.X; int xEnd = selectionRectangle.Location.X + selectionRectangle.Width; /*for (int y = yStart; y < yEnd; y++) * for (int x = xStart; x < xEnd; x++) * if (IsInPolygon(points.ToArray(), new Point(x, y))) * src.SetPixel(x, y, Color.White);*/ Point p = new Point(selectionRectangle.Left, selectionRectangle.Top); Data.Segment segm = new Data.Segment(target, p); segm.selectionStrategy = this; mainScene.AddSegment(segm); segmentIndex = mainScene.GetSegmentCount() - 1; }