/// <summary>
 /// ドット線を描写します。
 /// </summary>
 /// <param name="bitmap">ビットマップイメージ</param>
 /// <param name="margin">余白(左と上を使用)</param>
 /// <param name="begin">開始位置</param>
 /// <param name="end">終了位置</param>
 /// <param name="color">色</param>
 public static void DrawLineDotted(this WriteableBitmap bitmap, Thickness margin, Point begin, Point end, Color color, int dotSpace, int dotLength)
 {
     begin.X += margin.Left;
     begin.Y += margin.Top;
     end.X   += margin.Left;
     end.Y   += margin.Top;
     bitmap.DrawLineDotted(begin, end, color, dotSpace, dotLength);
     //bitmap.DrawLineDotted(new Point(begin.X + margin.Left, begin.Y + margin.Top), new Point(end.X + margin.Left, end.Y + margin.Top), color, dotSpace, dotLength);
 }
Esempio n. 2
0
        public static void DrawDotted(WriteableBitmap bitmap,
                                      Color backColor, Color grid5mmColor, Color grid1mmColor,
                                      int dotsPerMm)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException(nameof(bitmap));
            }

            bitmap.Clear(backColor);

            var dotsPer5mm = dotsPerMm * 5;

            // 5mm, horz
            for (int y = 0; y < bitmap.PixelHeight; y += dotsPer5mm)
            {
                bitmap.DrawLineDotted(0, y, bitmap.PixelWidth, y, 1, 1, grid5mmColor);
            }

            // 5mm, vert
            for (int x = 0; x < bitmap.PixelWidth; x += dotsPer5mm)
            {
                bitmap.DrawLineDotted(x, 0, x, bitmap.PixelHeight, 1, 1, grid5mmColor);
            }

            // 1mm
            for (int y = 0; y < bitmap.PixelHeight; y += dotsPerMm)
            {
                if (y % dotsPer5mm == 0)
                {
                    continue;
                }

                for (int x = 0; x < bitmap.PixelWidth; x += dotsPerMm)
                {
                    if (x % dotsPer5mm == 0)
                    {
                        continue;
                    }

                    bitmap.SetPixel(x, y, grid1mmColor);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// X軸とY軸の目盛り線を描写します。
        /// </summary>
        /// <param name="dc">レンダー</param>
        private void DrawXYScale(DateOrTimeSingleChart container, WriteableBitmap dc)
        {
            foreach (var i in Enumerable.Range(0, container.XScaleSplit + 1))
            {
                var x = GWidth / container.XScaleSplit * i;

                dc.DrawLineDotted(
                    Margin,
                    new Point(x, 1),
                    new Point(x, GHeight),
                    Color,
                    Util.DotSpace,
                    Util.DotLength
                    );

                dc.DrawLine(
                    Margin,
                    new Point(x, GHeight + Util.ScaleLineLength),
                    new Point(x, GHeight),
                    Color
                    );
            }

            foreach (var i in Enumerable.Range(0, YScaleSplit + 1))
            {
                var y = GHeight / YScaleSplit * i;

                dc.DrawLineDotted(
                    Margin,
                    new Point(0, y),
                    new Point(GWidth, y),
                    Color,
                    Util.DotSpace,
                    Util.DotLength
                    );

                dc.DrawLine(
                    Margin,
                    new Point(Util.ScaleLineLength * -1, y),
                    new Point(0, y),
                    Color
                    );
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Draws the different types of shapes.
        /// </summary>
        private void DrawStaticShapes()
        {
            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            using (writeableBmp.GetBitmapContext())
            {
                // Init some size vars
                int w    = this.writeableBmp.PixelWidth - 2;
                int h    = this.writeableBmp.PixelHeight - 2;
                int w3rd = w / 3;
                int h3rd = h / 3;
                int w6th = w3rd >> 1;
                int h6th = h3rd >> 1;

                // Clear
                writeableBmp.Clear();

                // Draw some points
                for (int i = 0; i < 200; i++)
                {
                    writeableBmp.SetPixel(rand.Next(w3rd), rand.Next(h3rd), GetRandomColor());
                }

                // Draw Standard shapes
                writeableBmp.DrawLine(rand.Next(w3rd, w3rd * 2), rand.Next(h3rd), rand.Next(w3rd, w3rd * 2), rand.Next(h3rd),
                                      GetRandomColor());
                writeableBmp.DrawTriangle(rand.Next(w3rd * 2, w - w6th), rand.Next(h6th), rand.Next(w3rd * 2, w),
                                          rand.Next(h6th, h3rd), rand.Next(w - w6th, w), rand.Next(h3rd),
                                          GetRandomColor());

                writeableBmp.DrawQuad(rand.Next(0, w6th), rand.Next(h3rd, h3rd + h6th), rand.Next(w6th, w3rd),
                                      rand.Next(h3rd, h3rd + h6th), rand.Next(w6th, w3rd),
                                      rand.Next(h3rd + h6th, 2 * h3rd), rand.Next(0, w6th), rand.Next(h3rd + h6th, 2 * h3rd),
                                      GetRandomColor());
                writeableBmp.DrawRectangle(rand.Next(w3rd, w3rd + w6th), rand.Next(h3rd, h3rd + h6th),
                                           rand.Next(w3rd + w6th, w3rd * 2), rand.Next(h3rd + h6th, 2 * h3rd),
                                           GetRandomColor());

                // Random polyline
                int[] p = new int[rand.Next(7, 10) * 2];
                for (int j = 0; j < p.Length; j += 2)
                {
                    p[j]     = rand.Next(w3rd * 2, w);
                    p[j + 1] = rand.Next(h3rd, 2 * h3rd);
                }
                writeableBmp.DrawPolyline(p, GetRandomColor());

                // Random closed polyline
                p = new int[rand.Next(6, 9) * 2];
                for (int j = 0; j < p.Length - 2; j += 2)
                {
                    p[j]     = rand.Next(w3rd);
                    p[j + 1] = rand.Next(2 * h3rd, h);
                }
                p[p.Length - 2] = p[0];
                p[p.Length - 1] = p[1];
                writeableBmp.DrawPolyline(p, GetRandomColor());

                // Ellipses
                writeableBmp.DrawEllipse(rand.Next(w3rd, w3rd + w6th), rand.Next(h3rd * 2, h - h6th),
                                         rand.Next(w3rd + w6th, w3rd * 2), rand.Next(h - h6th, h), GetRandomColor());
                writeableBmp.DrawEllipseCentered(w - w6th, h - h6th, w6th >> 1, h6th >> 1, GetRandomColor());

                // Draw Grid
                writeableBmp.DrawLineDotted(0, h3rd, w, h3rd, 2, 4, Colors.Black);
                writeableBmp.DrawLineDotted(0, 2 * h3rd, w, 2 * h3rd, 2, 4, Colors.Black);
                writeableBmp.DrawLineDotted(w3rd, 0, w3rd, h, 2, 4, Colors.Black);
                writeableBmp.DrawLineDotted(2 * w3rd, 0, 2 * w3rd, h, 2, 4, Colors.Black);

                // Invalidates on exit of using block
            }
        }
 /// <summary>
 /// ドット線を描写します。
 /// </summary>
 /// <param name="bitmap">ビットマップイメージ</param>
 /// <param name="begin">開始位置</param>
 /// <param name="end">終了位置</param>
 /// <param name="color">色</param>
 public static void DrawLineDotted(this WriteableBitmap bitmap, Point begin, Point end, Color color, int dotSpace, int dotLength)
 {
     bitmap.DrawLineDotted((int)begin.X + 1, (int)begin.Y + 1, (int)end.X + 1, (int)end.Y + 1, dotSpace, dotLength, color);
 }