コード例 #1
0
        public void RedrawScreen(List <Figure> listFig, int index, Canvas canvas)
        {
            //    canvas.Children.Clear();
            //    gridFigure.AddFigure(canvas);
            //    foreach (Line ln in centerLines)
            //        canvas.Children.Add(ln);
            //    if (OptionMode.mode == Mode.modeCursor)
            //        DrawFirstAndLastRectangle();
            //    for (int i = FigureList.Count -1 ; i >=0; i--)
            //    {
            //        FigureList[i].AddFigure(canvas);                        //можно не перерисовывать каждый раз
            //        if (AllRectanglesOn && i == ChosenFigure)
            //        {
            //            FigureList[i].DrawAllRectangles();
            //        }
            //    }
            //    if (OptionMode.mode == Mode.modeFigure || OptionMode.mode == Mode.modeTatami || OptionMode.mode == Mode.modeRunStitch
            //        || OptionMode.mode == Mode.modeSatin)
            //    {
            //        DrawInvisibleRectangles(canvas);
            //    }
            //    for (int i = 0; i < listPltFigure.Count; i++)
            //    {
            //        listPltFigure[i].AddFigure(canvas);
            //    }

            canvas.Children.Clear();
            canvas.Children.Add(gridBMP);
            WriteableBitmap bmp = BitmapFactory.New(1600, 900);

            bmp.Clear(Colors.Transparent);
            Color lineColor;

            for (int i = 0; i < listFig.Count; i++)
            {
                if (listFig[i].points.Count > 0)
                {
                    if (i == index)
                    {
                        lineColor = OptionColor.colorActive;
                    }
                    else
                    {
                        lineColor = OptionColor.colorInactive;
                    }
                    List <Point> pts = listFig[i].points;
                    for (int j = 0; j < pts.Count - 1; j++)
                    {
                        bmp.DrawLineBresenham((int)pts[j].X, (int)pts[j].Y, (int)pts[j + 1].X, (int)pts[j + 1].Y, lineColor);
                    }
                }
            }
            DrawModeRectangles(listFig, bmp);
            mainBMP = new Image
            {
                Stretch = Stretch.None,
                Source  = bmp
            };
            canvas.Children.Add(mainBMP);
        }
コード例 #2
0
/*
 *      /// <summary>
 *      ///     绘制最大值数据组波形
 *      /// </summary>
 *      private void RenderPath(float[] data) {
 *          float value;
 *          //Stopwatch watch = new Stopwatch();
 *          //watch.Start();
 *          //fmax = this.data.Max();
 *          //fmin = this.data.Min();
 *          SetYlabel(_fmax, _fmin);
 *          if (_fmax > _fmin) {
 *              var pf = new PathFigure();
 *              value = (data[0] - _fmin) * 100 / (_fmax - _fmin);
 *              pf.StartPoint = new Point(0, value);
 *              for (var i = 1; i < ValidPixelNum; i++) {
 *                  value = (int) ((data[i] - _fmin) * 100 / (_fmax - _fmin));
 *                  var ls = new LineSegment();
 *                  ls.Point = new Point(i, value);
 *                  pf.Segments.Add(ls);
 *              }
 *              var pg = new PathGeometry();
 *              pg.Figures.Add(pf);
 *              linePath.Data = pg;
 *          }
 *          //watch.Stop();
 *          //Console.WriteLine("通道频域波形  {0}",watch.ElapsedMilliseconds);
 *      }
 */

        /// <summary>
        ///     绘制平均值数据组波形
        /// </summary>
        //private void RenderPath2(float[] data)
        //{
        //	float fmax, fmin;
        //	float value;

        //	fmax = this.data.Max();
        //	fmin = this.data.Min();
        //	if (fmax > fmin)
        //	{
        //		PathFigure pf = new PathFigure();
        //		value = (data[0] - fmin) * 100 / (fmax - fmin);
        //		pf.StartPoint = new Point(0, value);
        //		for (int i = 1; i < ValidPixelNum; i++)
        //		{
        //			value = (int)((data[i] - fmin) * 100 / (fmax - fmin));
        //			LineSegment ls = new LineSegment();
        //			ls.Point = new Point(i, value);
        //			pf.Segments.Add(ls);
        //		}

        //		List<PathFigure> lstf = new List<PathFigure>();
        //		lstf.Add(pf);
        //		PathGeometry pg = new PathGeometry(lstf);
        //		this.AveragelinePath.Data = pg;
        //	}
        //}
        void RenderPath2(ref float[] src_data)
        {
            float fmax = this.fmax;
            float fmin = this.fmin;

            if (fmax > fmin)
            {
                double       min         = fmin;
                double       max         = fmax;
                DynamicAxis2 dynamicAxis = new DynamicAxis2 {
                    Pixles = 100, CanvasLine = canvas00, CanvasText = ycanvas00
                };
                dynamicAxis.Regulate(ref min, ref max, 4);
                fmin = (float)min;
                fmax = (float)max;

                WriteableBitmap wb     = BitmapFactory.New(1800, 100);
                Point           pstart = new Point();
                Point           pend   = new Point();

                float value1 = (src_data[0] - fmin) * 100 / (fmax - fmin);

                for (int i = 1; i < src_data.Length; i++)
                {
                    float value2 = (src_data[i] - fmin) * 100 / (fmax - fmin);
                    pstart.X = i - 1;
                    pstart.Y = value1;
                    pend.X   = i;
                    pend.Y   = value2;
                    value1   = value2;
                    wb.DrawLineBresenham((int)pstart.X, (int)pstart.Y, (int)pend.X, (int)pend.Y, Colors.Lime);
                }
                WaveImage.Source = wb;
            }
        }
コード例 #3
0
        /// <summary>
        /// Draws a colored line by connecting two points using the Bresenham algorithm.
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="x1">The x-coordinate of the start point.</param>
        /// <param name="y1">The y-coordinate of the start point.</param>
        /// <param name="x2">The x-coordinate of the end point.</param>
        /// <param name="y2">The y-coordinate of the end point.</param>
        /// <param name="color">The color for the line.</param>
        public static void DrawLineBresenham(this WriteableBitmap bmp, int x1, int y1, int x2, int y2, Color color)
        {
            // Add one to use mul and cheap bit shift for multiplicaltion
            int a   = color.A + 1;
            int col = (color.A << 24)
                      | ((byte)((color.R * a) >> 8) << 16)
                      | ((byte)((color.G * a) >> 8) << 8)
                      | ((byte)((color.B * a) >> 8));

            bmp.DrawLineBresenham(x1, y1, x2, y2, col);
        }
コード例 #4
0
        public void DrawLine(Point p1, Point p2, Canvas canvas)
        {
            canvas.Children.Remove(transparentBMP);
            WriteableBitmap bmp = BitmapFactory.New(1600, 900);

            bmp.Clear(Colors.Transparent);
            bmp.DrawLineBresenham((int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y, OptionColor.colorDrawing);
            transparentBMP = new Image
            {
                Stretch = Stretch.None,
                Source  = bmp
            };
            canvas.Children.Add(transparentBMP);
        }
コード例 #5
0
ファイル: ToolSet.cs プロジェクト: SiDzejj/PixiEditor
        /// <summary>
        /// Draws line in canvas
        /// </summary>
        /// <param name="layer">Layer to operate on</param>
        /// <param name="coordinates">Starting coordinates, usually click point</param>
        /// <param name="color">Does it really need a description?</param>
        private async void LineAsync(Layer layer, Coordinates coordinates, Color color, int size)
        {
            WriteableBitmap wb = layer.LayerBitmap;

            _toolIsExecuting = true;
            //clones bitmap before line
            WriteableBitmap writeableBitmap = wb.Clone();

            //While Mouse buttons are pressed, clears current bitmap, pastes cloned bitmap and draws line, on each iteration
            while (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed)
            {
                wb.Clear();
                wb.Blit(new Rect(new Size(layer.Width, layer.Height)), writeableBitmap, new Rect(new Size(layer.Width, layer.Height)), WriteableBitmapExtensions.BlendMode.Additive);
                wb.DrawLineBresenham(coordinates.X, coordinates.Y, _activeCoordinates.X, _activeCoordinates.Y, color);
                await Task.Delay(_asyncDelay);
            }
            _toolIsExecuting = false;
        }
コード例 #6
0
        void RenderPath(ref float[] imgdata)
        {
            float y_max = fMax;
            float y_min = fMin;

            if (!(y_max > y_min))
            {
                return;
            }
            CordAxis axisy = new CordAxis {
                CanvasLine = ycanvas01,
                CanvasText = ycanvas00,
                FMin       = y_min,
                FMax       = y_max,
                Num        = 4,
                Span       = 25
            };

            axisy.DrawAxis(ref y_min, ref y_max);

            WriteableBitmap wb     = BitmapFactory.New(1800, 100);
            Point           pstart = new Point();
            Point           pend   = new Point();

            float value1 = (imgdata[0] - y_min) * 100 / (y_max - y_min);

            for (int i = 1; i < imgdata.Length; i++)
            {
                float value2 = (imgdata[i] - y_min) * 100 / (y_max - y_min);
                pstart.X = i - 1;
                pstart.Y = value1;
                pend.X   = i;
                pend.Y   = value2;
                value1   = value2;
                wb.DrawLineBresenham((int)pstart.X, (int)pstart.Y, (int)pend.X, (int)pend.Y,
                                     Colors.YellowGreen);
            }
            image.Source = wb;
        }
コード例 #7
0
        private void DrawStroke(List <int> bitmapPixels, int width, int height)
        {
            var    stroke         = (fastRangeAreaBitmapSeries.Stroke as SolidColorBrush).Color;
            double leftThickness  = fastRangeAreaBitmapSeries.StrokeThickness / 2;
            double rightThickness = (fastRangeAreaBitmapSeries.StrokeThickness % 2 == 0
                                            ? (fastRangeAreaBitmapSeries.StrokeThickness / 2) - 1
                                            : fastRangeAreaBitmapSeries.StrokeThickness / 2);
            int xStart, yStart, xEnd, yEnd;

            xStart = areaPoints[0];
            yStart = areaPoints[1];
            xEnd   = areaPoints[2];
            yEnd   = areaPoints[3];

            if (points1 == null)
            {
                points1 = new int[10];
            }

            GetLinePoints(xStart, yStart, xEnd, yEnd, leftThickness, rightThickness, points1);
            double[] emptyStrokeIndexes = GetEmptyStrokeIndexes();
            var      isMultipleArea     = fastRangeAreaBitmapSeries.Area.IsMultipleArea;

            for (int i = 2, j = 0; i < areaPoints.Count;)
            {
                points2 = new int[10];
                xStart  = xEnd;
                yStart  = yEnd;
                i       = i + 2;

                if (i + 1 < areaPoints.Count)
                {
                    xEnd = areaPoints[i];
                    yEnd = areaPoints[i + 1];
                    UpdatePoints2(xStart, yStart, xEnd, yEnd, leftThickness, rightThickness);
                }

                if (emptyStrokeIndexes[0] != j && emptyStrokeIndexes[1] != j)
                {
                    if (isMultipleArea && fastRangeAreaBitmapSeries.Clip != null)
                    {
                        var clip = fastRangeAreaBitmapSeries.Clip.Bounds;

                        bitmap.DrawLineBresenham(fastBuffer, width, height, points1[0], points1[1], points1[2], points1[3], stroke, bitmapPixels, clip);
                        bitmap.FillPolygon(fastBuffer, points1, width, height, stroke, bitmapPixels, clip);
                        bitmap.DrawLineBresenham(fastBuffer, width, height, points1[4], points1[5], points1[6], points1[7], stroke, bitmapPixels, clip);
                    }
                    else
                    {
                        bitmap.DrawLineAa(fastBuffer, width, height, points1[0], points1[1], points1[2], points1[3], stroke, bitmapPixels);
                        bitmap.FillPolygon(fastBuffer, points1, width, height, stroke, bitmapPixels);
                        bitmap.DrawLineAa(fastBuffer, width, height, points1[4], points1[5], points1[6], points1[7], stroke, bitmapPixels);
                    }
                }

                j       = j + 2;
                points1 = points2;
                points2 = null;
            }

            points1 = null;
            points2 = null;
        }