本文整理汇总了C#中Microsoft.Graphics.Canvas.CanvasDrawingSession.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# CanvasDrawingSession.Clear方法的具体用法?C# CanvasDrawingSession.Clear怎么用?C# CanvasDrawingSession.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Graphics.Canvas.CanvasDrawingSession
的用法示例。
在下文中一共展示了CanvasDrawingSession.Clear方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCanvasState
private void DrawCanvasState(CanvasControl canvas, CanvasDrawingSession ds, int drawCount)
{
ds.Clear(Color.FromArgb(0, 0, 0, 0));
ds.DrawLine(0, 0, (float)canvas.ActualWidth, (float)canvas.ActualHeight, Colors.Aqua);
ds.DrawLine(0, (float)canvas.ActualHeight, (float)canvas.ActualWidth, 0, Colors.Aqua);
var text = String.Format("{0}x{1}\n{2} redraws", (int)canvas.ActualWidth, (int)canvas.ActualHeight, drawCount);
ds.DrawText(
text,
0, 0,
Colors.FloralWhite,
new CanvasTextFormat()
{
VerticalAlignment = CanvasVerticalAlignment.Top,
ParagraphAlignment = ParagraphAlignment.Left,
FontSize = 10
});
}
示例2: Draw
/// <summary>
///
/// </summary>
/// <param name="ds"></param>
private void Draw(CanvasDrawingSession ds)
{
ds.Antialiasing = CanvasAntialiasing.Aliased;
ds.TextAntialiasing = CanvasTextAntialiasing.Auto;
ds.Clear(Colors.Transparent);
var renderer = _context.Editor.Renderers[0];
var container = _context.Editor.Project.CurrentContainer;
if (container == null)
return;
var t = Matrix3x2.CreateTranslation((float)_state.PanX, (float)_state.PanY);
var s = Matrix3x2.CreateScale((float)_state.Zoom);
var old = ds.Transform;
ds.Transform = s * t;
var template = container.Template;
if (template != null)
{
DrawBackground(
ds,
template.Background,
template.Width,
template.Height);
renderer.Draw(
ds,
template,
container.Data.Properties,
null);
}
else
{
DrawBackground(
ds,
container.Background,
container.Width,
container.Height);
}
renderer.Draw(
ds,
container,
container.Data.Properties,
null);
if (container.WorkingLayer != null)
{
renderer.Draw(
ds,
container.WorkingLayer,
container.Data.Properties,
null);
}
if (container.HelperLayer != null)
{
renderer.Draw(
ds,
container.HelperLayer,
container.Data.Properties,
null);
}
ds.Transform = old;
}
示例3: DrawTile
static void DrawTile(CanvasDrawingSession ds, float width, float height)
{
using (var cl = new CanvasCommandList(ds))
{
using (var clds = cl.CreateDrawingSession())
{
var text = string.Format("{0}\n{1}", DateTime.Now.ToString("ddd"), DateTime.Now.ToString("HH:mm"));
var textFormat = new CanvasTextFormat()
{
FontFamily = "Segoe UI Black",
HorizontalAlignment = CanvasHorizontalAlignment.Right,
VerticalAlignment = CanvasVerticalAlignment.Center,
FontSize = 20,
LineSpacing = 20
};
clds.DrawText(text, 0, 0, Colors.White, textFormat);
}
var effect = new GaussianBlurEffect()
{
Source = cl,
BlurAmount = 1,
};
ds.Clear(Colors.Orange);
var bounds = effect.GetBounds(ds);
var ratio = bounds.Height / bounds.Width;
var destHeight = height * ratio;
ds.DrawImage(effect, new Rect(0, height / 2 - destHeight / 2, width, destHeight), bounds);
ds.DrawText(string.Format("Generated by Win2D\n{0}\n{1}", DateTime.Now.ToString("d"), DateTime.Now.ToString("t")),
12, 12, Colors.Black,
new CanvasTextFormat()
{
HorizontalAlignment = CanvasHorizontalAlignment.Left,
VerticalAlignment = CanvasVerticalAlignment.Top,
FontSize = 12
});
}
}
示例4: Draw
public void Draw(CanvasDrawingSession session)
{
session.Clear(clearColor);
foreach (var particle in particles)
{
//Testing
//session.FillCircle(new Vector2(particle.X, particle.Y), 20f, Colors.Red);
particle.Draw(session);
}
}
示例5: Draw
private void Draw(CanvasDrawingSession ds)
{
ds.Antialiasing = CanvasAntialiasing.Aliased;
ds.TextAntialiasing = CanvasTextAntialiasing.Auto;
ds.Clear(Colors.Transparent);
var renderer = _context.Editor.Renderers[0];
var container = _context.Editor.Project.CurrentContainer;
if (container.Template != null)
{
DrawBackground(
ds,
container.Template.Background,
container.Width,
container.Height);
renderer.Draw(
ds,
container.Template,
container.Properties,
null);
}
DrawBackground(
ds,
container.Background,
container.Width,
container.Height);
renderer.Draw(
ds,
container,
container.Properties,
null);
if (container.WorkingLayer != null)
{
renderer.Draw(
ds,
container.WorkingLayer,
container.Properties,
null);
}
if (container.HelperLayer != null)
{
renderer.Draw(
ds,
container.HelperLayer,
container.Properties,
null);
}
}
示例6: 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;
//.........这里部分代码省略.........
示例7: DrawBackground
private void DrawBackground(CanvasDrawingSession ds, Matrix3x2 transform)
{
const int levelUpTime = 60;
// After levelling up we flash the screen white for a bit
Color normalColor = Colors.Blue;
Color levelUpFlashColor = Colors.White;
var flashAmount = Math.Min(1, (leveledUpTimer / (float)levelUpTime));
ds.Clear(InterpolateColors(normalColor, levelUpFlashColor, flashAmount));
var topLeft = Vector2.Transform(new Vector2(0, 0), transform);
var bottomRight = Vector2.Transform(new Vector2(1, 1), transform);
var middle = (bottomRight.X - topLeft.X) / 2 + topLeft.X;
// and display some text to let the player know what happened
if (leveledUpTimer < levelUpTime * 2)
{
ds.DrawText("Level Up!", middle, 0, Colors.White, levelUpFormat);
}
// Draw some lines to show where the top / bottom of the play area is.
var topLine = topLeft.Y - Letter.TextFormat.FontSize;
var bottomLine = bottomRight.Y + Letter.TextFormat.FontSize;
Color lineColor = levelUpFlashColor;
lineColor.A = 128;
ds.DrawLine(0, topLine, bottomRight.X, topLine, lineColor, 3);
ds.DrawLine(0, bottomLine, bottomRight.X, bottomLine, lineColor, 3);
}
示例8: DrawFrame
private void DrawFrame(CanvasDrawingSession ds)
{
ds.Clear();
if (_background != null)
{
var tile = new TileEffect();
tile.Source = _background;
tile.SourceRectangle = new Rect(0, 0, 400, 400);
ds.DrawImage(tile);
}
using (var blendDs = _buffer.CreateDrawingSession())
{
blendDs.Clear();
}
foreach (var layer in _layers.Reverse().Where(l => l.IsVisible))
{
using (var tmpDs = _tmpBuffer.CreateDrawingSession())
{
tmpDs.Clear(Colors.Transparent);
switch (layer.BlendMode)
{
case BlendMode.Normal:
tmpDs.DrawImage(_buffer);
tmpDs.DrawImage(layer.Image, (float)layer.Opacity / 100);
break;
case BlendMode.Addition:
tmpDs.DrawImage(_buffer);
tmpDs.Blend = CanvasBlend.Add;
tmpDs.DrawImage(layer.Image, (float)layer.Opacity / 100);
break;
default:
using (var alpha = layer.Image.Clone())
using (var blend = new BlendEffect())
{
using (var alphaDs = alpha.CreateDrawingSession())
{
alphaDs.DrawImage(layer.Image, (float)layer.Opacity / 100);
}
blend.Background = _buffer;
blend.Foreground = alpha;
blend.Mode = layer.BlendMode.ToBlendEffectMode();
tmpDs.DrawImage(blend);
}
break;
}
}
using (var blendDs = _buffer.CreateDrawingSession())
{
blendDs.Clear();
blendDs.DrawImage(_tmpBuffer);
}
ds.DrawImage(_buffer);
}
}