本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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");
}
}
示例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;
//.........这里部分代码省略.........