Beispiel #1
0
        private void drawSplineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_points.Count == 0)
            {
                return;
            }

            float[] ex;
            float[] ey;


            CubicSpline.FitParametric(_points.Select(x => x.X).ToArray(), _points.Select(x => x.Y).ToArray(), _points.Count * 100, out ex, out ey);
            using (Graphics g = Graphics.FromImage(MainImage.Image))
            {
                for (int i = 1; i < _points.Count; i++)
                {
                    g.DrawLine(new Pen(Color.Green, 1), _points[i - 1], _points[i]);
                }

                for (int i = 1; i < ex.Length; i++)
                {
                    g.DrawLine(new Pen(Color.Red, 2), ex[i - 1], ey[i - 1], ex[i], ey[i]);
                }

                g.DrawCurve(new Pen(Color.Blue), _points.ToArray());
            }
            MainImage.Invalidate();
            MessageBox.Show("RED: Spline interpolation\r\nBLUE: C# Curve line\r\nGREEN: Line by points", "INFO",
                            MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
Beispiel #2
0
        private async void UndoExecute()
        {
            _buffer        = new int[MainImage.PixelWidth * MainImage.PixelHeight];
            _maskBuffer    = new byte[MainImage.PixelWidth * MainImage.PixelHeight];
            _filterApplied = false;

            _originalStream.Seek(0, SeekOrigin.Begin);
            _editingSession = await EditingSessionFactory.CreateEditingSessionAsync(_originalStream);

            await _editingSession.RenderToWriteableBitmapAsync(MainImage);

            MainImage.Invalidate();

            CanApply   = false;
            _noChanges = true;
            UndoCommand.RaiseCanExecuteChanged();

            if (PreviewImage != null)
            {
                for (var i = 0; i < PreviewImage.Pixels.Length; ++i)
                {
                    PreviewImage.Pixels[i] = 0;
                }
                PreviewImage.Invalidate();
            }

            BindTool();
        }
Beispiel #3
0
        private void MainImage_MouseMove(object sender, MouseEventArgs e)
        {
            if (MainImage.Image == null)
            {
                return;
            }

            if (_painted)
            {
                int r = new Random().Next(0, 10);
                if (r % 2 == 0)
                {
                    return;
                }

                if (_points.Where(x => (int)x.Y == e.Y && (int)x.X == e.X).ToList().Count == 0)
                {
                    _points.Add(e.Location);
                    using (Graphics g = Graphics.FromImage((Bitmap)MainImage.Image))
                    {
                        g.DrawRectangle(new Pen(Color.Green), e.X, e.Y, 1, 1);
                    }
                    MainImage.Invalidate();
                }
            }
        }