当前位置: 首页>>代码示例>>C#>>正文


C# CanvasDrawingSession.DrawRectangle方法代码示例

本文整理汇总了C#中Microsoft.Graphics.Canvas.CanvasDrawingSession.DrawRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# CanvasDrawingSession.DrawRectangle方法的具体用法?C# CanvasDrawingSession.DrawRectangle怎么用?C# CanvasDrawingSession.DrawRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Graphics.Canvas.CanvasDrawingSession的用法示例。


在下文中一共展示了CanvasDrawingSession.DrawRectangle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawSquare

        private void DrawSquare(CanvasControl sender, CanvasDrawingSession ds)
        {
            var width = (float) sender.ActualWidth;
            var height = (float) sender.ActualHeight;
            var stroke = this.defaultStroke;
            var min = Math.Min(width, height);
            min -=  stroke * 2;

            var rect = new Rect(stroke, stroke, min, min);
            ds.FillRectangle(rect, ForegroundColor);
            ds.DrawRectangle(rect, GlowColor, stroke);
        }
开发者ID:shanselman,项目名称:BabySmashWindows10,代码行数:12,代码来源:GlowShapeCustomControl.cs

示例2: DrawSelectionBoundingRect

        private void DrawSelectionBoundingRect(CanvasDrawingSession ds)
        {
            if (selectionBoundingRect == null ||
                selectionBoundingRect.Value.Width == 0 ||
                selectionBoundingRect.Value.Height == 0 ||
                selectionBoundingRect.Value.IsEmpty)
            {
                return;
            }

            ds.DrawRectangle(selectionBoundingRect.Value, Colors.Magenta);
        }
开发者ID:SarahAnnTolsma,项目名称:Win2D,代码行数:12,代码来源:InkExample.xaml.cs

示例3: DrawSourceImage

            double DrawSourceImage(CanvasDrawingSession ds, Rect sourceRect, float width)
            {
                var sourceImageOffsetX = (float)((width / 2) - (sourceBitmap.Size.Width / 2));
                var sourceImageOffsetY = (float)(10);
                ds.DrawImage(sourceBitmap, sourceImageOffsetX, sourceImageOffsetY);

                sourceRect.X += sourceImageOffsetX;
                sourceRect.Y += sourceImageOffsetY;
                ds.DrawRectangle(sourceRect, Colors.Yellow, 1, hairline);

                return sourceImageOffsetY + sourceBitmap.Size.Height * 1.2;
            }
开发者ID:fengweijp,项目名称:Win2D,代码行数:12,代码来源:DrawImageEmulations.xaml.cs

示例4: DrawGrid

        private void DrawGrid(CanvasDrawingSession ds, Vector2 cellAcross, Vector2 cellDown, Vector2 topLeft)
        {
            var gridTopLeft = topLeft;
            var gridBottomRight = topLeft + cellAcross * columns + cellDown * rows;

            ds.DrawRectangle(new Rect(gridTopLeft.ToPoint(), gridBottomRight.ToPoint()), Colors.Black, 1);

            for (int row = 0; row <= rows; ++row)
            {
                ds.DrawLine(topLeft + cellDown * row, topLeft + cellAcross * columns + cellDown * row, Colors.Black, 1);
            }

            for (int column = 0; column <= columns; ++column)
            {
                ds.DrawLine(topLeft + cellAcross * column, topLeft + cellAcross * column + cellDown * rows, Colors.Black, 1);
            }
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:17,代码来源:PrintingExample.xaml.cs

示例5: Draw

            public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height)
            {
                var sz = sourceBitmap.Size;
                Rect sourceRect = new Rect(
                    sz.Width * 0.25 + Math.Sin(frameCounter * 0.02) * (sz.Width * 0.5),
                    sz.Height * 0.25 + Math.Cos(frameCounter * 0.01) * (sz.Height * 0.5),
                    sz.Width * 0.5,
                    sz.Height * 0.5);

                double y = DrawSourceImage(ds, sourceRect, width);

                double displayWidth = width / 2;
                double x = displayWidth;
                double destHeight = (height - y) / 3;

                Rect bitmapDestRect = new Rect(x, y + 5, displayWidth, destHeight - 10);
                y += destHeight;

                Rect bitmapDestRect2 = new Rect(x, y + 5, displayWidth, destHeight - 10);
                y += destHeight;

                Rect effectDestRect = new Rect(x, y + 5, displayWidth, destHeight - 10);

                var format = new CanvasTextFormat()
                {
                    FontSize = 14,
                    HorizontalAlignment = CanvasHorizontalAlignment.Right,
                    VerticalAlignment = CanvasVerticalAlignment.Center
                };

                ds.DrawText("D2D DrawBitmap", 0, (float)bitmapDestRect.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format);
                ds.DrawText("D2D DrawImage (bitmap)", 0, (float)bitmapDestRect2.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format);
                ds.DrawText("D2D DrawImage (effect)", 0, (float)effectDestRect.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format);

                ds.FillRectangle(bitmapDestRect, fillPattern);
                ds.FillRectangle(bitmapDestRect2, fillPattern);
                ds.FillRectangle(effectDestRect, fillPattern);

                ds.DrawImage(sourceBitmap, bitmapDestRect, sourceRect);
                ds.DrawImage(sourceBitmap, bitmapDestRect2, sourceRect, 1, CanvasImageInterpolation.Cubic);
                ds.DrawImage(sourceEffect, effectDestRect, sourceRect);

                ds.DrawRectangle(bitmapDestRect, Colors.Yellow, 1, hairline);
                ds.DrawRectangle(bitmapDestRect2, Colors.Yellow, 1, hairline);
                ds.DrawRectangle(effectDestRect, Colors.Yellow, 1, hairline);
            }
开发者ID:fengweijp,项目名称:Win2D,代码行数:46,代码来源:DrawImageEmulations.xaml.cs

示例6: DrawRectangle

        private void DrawRectangle(CanvasControl sender, CanvasDrawingSession ds)
        {
            var width = (float)sender.ActualWidth;
            var height = (float)sender.ActualHeight;

            int steps = Math.Min((int)(width / 10), 20);

            for (int i = 0; i < steps; ++i)
            {
                var mu = (float)i / steps;

                var color = GradientColor(mu);

                mu *= 0.5f;
                var x = mu * width;
                var y = mu * height;

                var xx = (1 - mu) * width;
                var yy = (1 - mu) * height;

                ds.DrawRectangle(x, y, xx - x, yy - y, color, 2.0f);
            }
        }
开发者ID:jiatingxiu,项目名称:Win2D,代码行数:23,代码来源:ShapesExample.xaml.cs

示例7: DrawRectangleInternal

        private static void DrawRectangleInternal(
            CanvasDrawingSession ds,
            Color brush,
            Color pen,
            CanvasStrokeStyle ss,
            bool isStroked,
            bool isFilled,
            ref Rect2 rect,
            double strokeWidth)
        {
            if (isFilled)
            {
                ds.FillRectangle(
                    (float)rect.X,
                    (float)rect.Y,
                    (float)rect.Width,
                    (float)rect.Height,
                    brush);
            }

            if (isStroked)
            {
                ds.DrawRectangle(
                    (float)rect.X,
                    (float)rect.Y,
                    (float)rect.Width,
                    (float)rect.Height,
                    pen,
                    (float)strokeWidth,
                    ss);
            }
        }
开发者ID:monocraft,项目名称:Test2d,代码行数:32,代码来源:Win2dRenderer.cs

示例8: DrawSourceGraphic

        void DrawSourceGraphic(PerDeviceResources resources, CanvasDrawingSession ds, float offset)
        {
            var source = GetSourceBitmap(resources);

            if (source != null)
            {
                // We can either draw a precreated bitmap...
                ds.DrawImage(source, offset, offset);
            }
            else
            {
                // ... or directly draw some shapes.
                ds.FillRectangle(offset, offset, testSize, testSize, Colors.Gray);

                ds.DrawLine(offset, offset, offset + testSize, offset + testSize, Colors.Red);
                ds.DrawLine(offset + testSize, offset, offset, offset + testSize, Colors.Red);

                ds.DrawRectangle(offset + 0.5f, offset + 0.5f, testSize - 1, testSize - 1, Colors.Blue);

                ds.DrawText("DPI test", new Vector2(offset + testSize / 2), Colors.Blue, resources.TextFormat);

                resources.AddMessage("DrawingSession ->\n");
            }
        }
开发者ID:fengweijp,项目名称:Win2D,代码行数:24,代码来源:DpiExample.xaml.cs

示例9: DrawStuff

        void DrawStuff(CanvasDrawingSession ds)
        {
            int horizontalLimit = (int)m_canvasControl.ActualWidth;
            int verticalLimit = (int)m_canvasControl.ActualHeight;
            const float thickStrokeWidth = 80.0f;

            DrawnContentType drawnContentType = (DrawnContentType)m_drawnContentTypeCombo.SelectedValue;

            ds.Clear(NextRandomColor());
                
            Rect rect;
            Vector2 point;
            float radiusX;
            float radiusY;

            switch (drawnContentType)
            {
                case DrawnContentType.Clear_Only:
                    break;

                case DrawnContentType.Bitmap:
                    if (m_bitmap_tiger != null)
                    {
                        ds.DrawImage(m_bitmap_tiger, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2());
                    }
                    else
                    {
                        DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                    }
                    break;

                case DrawnContentType.Effect_Blur:
                    if (m_bitmap_tiger != null)
                    {
                        GaussianBlurEffect blurEffect = new GaussianBlurEffect();
                        blurEffect.StandardDeviation = 2.0f;
                        blurEffect.Source = m_bitmap_tiger;
                        ds.DrawImage(blurEffect, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2());
                    }
                    else
                    {
                        DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                    }
                    break;

                case DrawnContentType.Line_Thin:
                    ds.DrawLine(
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomColor());
                    break;

                case DrawnContentType.Line_Thick:
                    ds.DrawLine(
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                        NextRandomColor(),
                        thickStrokeWidth);
                    break;

                case DrawnContentType.Rectangle_Thin:
                    ds.DrawRectangle(
                        NextRandomRect(horizontalLimit, verticalLimit),
                        NextRandomColor());
                    break;

                case DrawnContentType.Rectangle_Thick:
                    ds.DrawRectangle(
                        NextRandomRect(horizontalLimit, verticalLimit),
                        NextRandomColor(),
                        thickStrokeWidth);
                    break;

                case DrawnContentType.Rectangle_Filled:
                    ds.FillRectangle(
                        NextRandomRect(horizontalLimit, verticalLimit),
                        NextRandomColor());
                    break;

                case DrawnContentType.RoundedRectangle_Thin:
                    NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY);
                    ds.DrawRoundedRectangle(
                        rect, radiusX, radiusY,
                        NextRandomColor());
                    break;

                case DrawnContentType.RoundedRectangle_Thick:
                    NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY);
                    ds.DrawRoundedRectangle(
                        rect, radiusX, radiusY,
                        NextRandomColor(),
                        thickStrokeWidth);
                    break;

                case DrawnContentType.Ellipse_Thin:
                    NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY);
                    ds.DrawEllipse(
                        point, radiusX, radiusY,
                        NextRandomColor());
                    break;
//.........这里部分代码省略.........
开发者ID:gfcprogramer,项目名称:Win2D,代码行数:101,代码来源:MainPage.xaml.cs


注:本文中的Microsoft.Graphics.Canvas.CanvasDrawingSession.DrawRectangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。