public override void Draw()
        {
            foreach (var penLine in _penLines)
            {
                foreach (var point in penLine.GetPoints())
                {
                    var pixelSize = penLine.Size;
                    var pointX    = point.X;
                    var pointY    = point.Y;

                    for (int i = pointX - pixelSize; i < pointX + pixelSize; i++)
                    {
                        for (int j = pointY - pixelSize; j < pointY + pixelSize; j++)
                        {
                            if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j)))
                            {
                                continue;
                            }

                            var newPoint = new BPoint(i, j, point.Color);

                            _bitmap.SetPixel(newPoint);
                        }
                    }
                }
            }
        }
示例#2
0
        public void Fill(IBPoint point, Color fillingColor)
        {
            _fillingColor = _bitmap.GetPixel(point.X, point.Y);

            Stack <Point> pixels = new Stack <Point>();

            pixels.Push(new Point(point.X, point.Y));

            while (pixels.Count > 0)
            {
                Point a = pixels.Pop();
                if (!CanvasValidator.IsCursorOutsideCanvas(a))
                {
                    var col = _bitmap.GetPixel(a.X, a.Y);

                    if (col.ToArgb().Equals(_fillingColor.ToArgb()) && !col.ToArgb().Equals(Setting.SelectedColor.ToArgb()))
                    {
                        _bitmap.SetPixel(a.X, a.Y, Setting.SelectedColor);
                        pixels.Push(new Point(a.X - 1, a.Y));
                        pixels.Push(new Point(a.X + 1, a.Y));
                        pixels.Push(new Point(a.X, a.Y - 1));
                        pixels.Push(new Point(a.X, a.Y + 1));
                    }
                }
            }
        }
        public override void PreviewDrawing(HashSet <Point> mousePositions)
        {
            if (mousePositions.Count == 1)
            {
                _lastPreviewCirclePoints = new HashSet <IBPoint>();
            }

            foreach (var point in _lastPreviewCirclePoints)
            {
                _bitmap.SetPixel(point.X, point.Y, point.Color);
            }

            _lastPreviewCirclePoints = new HashSet <IBPoint>();

            var startPoint = mousePositions.ElementAt(0);
            var endPoint   = mousePositions.ElementAt(mousePositions.Count - 1);

            var center = new Point((startPoint.X + endPoint.X) / 2, (startPoint.Y + endPoint.Y) / 2);
            var radius = (int)CustomPoint.GetDistance(startPoint.X, startPoint.Y, center.X, center.Y);

            var points = _circleAlgorithm.GetCirclePoints(BPoint.ConvertPointToIBPoint(center), radius);

            var finalPoints = new List <IBPoint>();

            var pixelSize  = Setting.SelectedPixelSize;
            var pixelColor = Setting.SelectedColor;

            foreach (var point in points)
            {
                for (int i = point.X - pixelSize; i < point.X + pixelSize; i++)
                {
                    for (int j = point.Y - pixelSize; j < point.Y + pixelSize; j++)
                    {
                        if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j)))
                        {
                            continue;
                        }

                        var newPoint = new BPoint(i, j, pixelColor);

                        var currentPixel = _bitmap.GetPixel(i, j);

                        var bPoint = new BPoint(i, j, Color.FromArgb(currentPixel.A, currentPixel.R, currentPixel.G, currentPixel.B));
                        _lastPreviewCirclePoints.Add(bPoint);

                        _bitmap.SetPixel(newPoint);
                    }
                }
            }
        }
        public override void PreviewDrawing(HashSet <Point> mousePositions)
        {
            if (mousePositions.Count == 1)
            {
                _lastPreviewPoints = new HashSet <IBPoint>();
            }

            var startPoint = mousePositions.ElementAt(0);
            var endPoint   = mousePositions.ElementAt(mousePositions.Count - 1);

            var linePoints = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);

            if (mousePositions.Count == 1)
            {
                _lastPreviewPoints = new HashSet <IBPoint>();
            }

            foreach (var point in _lastPreviewPoints)
            {
                _bitmap.SetPixel(point.X, point.Y, point.Color);
            }

            _lastPreviewPoints = new HashSet <IBPoint>();

            var pixelSize  = Setting.SelectedPixelSize;
            var pixelColor = Setting.SelectedColor;

            foreach (var point in linePoints)
            {
                for (int i = point.X - pixelSize; i < point.X + pixelSize; i++)
                {
                    for (int j = point.Y - pixelSize; j < point.Y + pixelSize; j++)
                    {
                        if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j)))
                        {
                            continue;
                        }

                        var newPoint = new BPoint(i, j, pixelColor);

                        var currentPixel = _bitmap.GetPixel(i, j);

                        var bPoint = new BPoint(i, j, Color.FromArgb(currentPixel.A, currentPixel.R, currentPixel.G, currentPixel.B));
                        _lastPreviewPoints.Add(bPoint);

                        _bitmap.SetPixel(newPoint);
                    }
                }
            }
        }
        public override void PreviewDrawing(HashSet <Point> points)
        {
            if (points.Count < 0)
            {
                return;
            }

            if (points.Count == 1)
            {
                var point = points.ElementAt(0);

                _bitmap.SetPixel(new BPoint(point.X, point.Y));
            }
            else
            {
                var startPoint = points.ElementAt(points.Count - 2);
                var endPoint   = points.ElementAt(points.Count - 1);

                var linePoints = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);

                _bitmap.SetPixel(BPoint.ConvertPointToIBPoint(startPoint));
                _bitmap.SetPixel(BPoint.ConvertPointToIBPoint(endPoint));

                foreach (var point in linePoints)
                {
                    var pixelSize = Setting.SelectedPixelSize;
                    var pointX    = point.X;
                    var pointY    = point.Y;

                    for (int i = pointX - pixelSize; i < pointX + pixelSize; i++)
                    {
                        for (int j = pointY - pixelSize; j < pointY + pixelSize; j++)
                        {
                            if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j)))
                            {
                                continue;
                            }

                            var newPoint = new BPoint(i, j, Setting.SelectedColor);

                            _bitmap.SetPixel(newPoint);
                        }
                    }
                }
            }
        }
示例#6
0
        public override void PreviewDrawing(HashSet <Point> mousePositions)
        {
            if (mousePositions.Count == 1)
            {
                _lastPreviewPoints = new HashSet <IBPoint>();
            }

            foreach (var point in _lastPreviewPoints)
            {
                _bitmap.SetPixel(point.X, point.Y, point.Color);
            }

            var startPoint = mousePositions.ElementAt(0);
            var endPoint   = mousePositions.ElementAt(mousePositions.Count - 1);
            var radius     = (int)BPoint.GetDistance(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);

            var leftPoint  = new BPoint(0, 0);
            var rightPoint = new BPoint(0, 0);

            //Check if mouse is under start point or above
            if (startPoint.Y > endPoint.Y)
            {
                leftPoint  = new BPoint(startPoint.X - radius, startPoint.Y - radius);
                rightPoint = new BPoint(startPoint.X + radius, startPoint.Y - radius);
            }
            else
            {
                leftPoint  = new BPoint(startPoint.X - radius, startPoint.Y + radius);
                rightPoint = new BPoint(startPoint.X + radius, startPoint.Y + radius);
            }

            var pointsFromStartToLeft  = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, leftPoint.X, leftPoint.Y);
            var pointsFromStartToRight = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, rightPoint.X, rightPoint.Y);
            var pointsFromLeftToRight  = _bresenhamLine.GetPointsOnLine(leftPoint.X, leftPoint.Y, rightPoint.X, rightPoint.Y);

            var megredPoints = pointsFromStartToLeft.Concat(pointsFromStartToRight);

            megredPoints = megredPoints.Concat(pointsFromLeftToRight);

            foreach (var point in megredPoints)
            {
                var pixelSize = Setting.SelectedPixelSize;
                var pointX    = point.X;
                var pointY    = point.Y;

                for (int i = pointX - pixelSize; i < pointX + pixelSize; i++)
                {
                    for (int j = pointY - pixelSize; j < pointY + pixelSize; j++)
                    {
                        if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j)))
                        {
                            continue;
                        }

                        var newPoint = new BPoint(i, j, Setting.SelectedColor);

                        var currentPixel = _bitmap.GetPixel(i, j);

                        var bPoint = new BPoint(i, j, Color.FromArgb(currentPixel.A, currentPixel.R, currentPixel.G, currentPixel.B));
                        _lastPreviewPoints.Add(bPoint);

                        _bitmap.SetPixel(newPoint);
                    }
                }
            }
        }