public override void Draw(CanvasDrawingSession drawingSession, bool useSpriteBatch) { if (!surfaceLoaded) { return; } // 保护原先画布的混合模式 var previousBlend = drawingSession.Blend; drawingSession.Blend = blendState; #if WINDOWS_UWP if (useSpriteBatch) { // 使用 SpriteBatch 可以提高性能 using (var spriteBatch = drawingSession.CreateSpriteBatch()) { Draw(drawingSession, spriteBatch); } } else { Draw(drawingSession, null); } #else Draw(drawingSession); #endif drawingSession.Blend = previousBlend; }
public void RunScenario(CanvasDrawingSession drawingSession, CanvasSpriteSortMode sortMode) { switch (method) { case Scenario.DrawMethod.Win2DSpriteBatch: using (var sb = drawingSession.CreateSpriteBatch(sortMode)) { foreach (var sprite in sprites) { sb.Draw(sprite.Bitmap, sprite.Position, sprite.Tint, Vector2.Zero, sprite.Rotation, Vector2.One, CanvasSpriteFlip.None); } } break; case Scenario.DrawMethod.DrawImage: var oldTransform = drawingSession.Transform; foreach (var sprite in sprites) { drawingSession.Transform = Matrix3x2.CreateRotation(sprite.Rotation) * Matrix3x2.CreateTranslation(sprite.Position); drawingSession.DrawImage(sprite.Bitmap, Vector2.Zero, sprite.Bitmap.Bounds, sprite.Tint.W); } drawingSession.Transform = oldTransform; break; } }
public void Draw(CanvasDrawingSession drawingSession, bool useSpriteBatch) { if (surfaceLoaded) { // 保护原先画布的混合模式 var previousBlend = drawingSession.Blend; drawingSession.Blend = CanvasBlend.SourceOver; #if WINDOWS_UWP if (useSpriteBatch) { // 使用 SpriteBatch 可以提高性能 using (var spriteBatch = drawingSession.CreateSpriteBatch()) { Draw(drawingSession, spriteBatch); } } else { Draw(drawingSession, null); } #else Draw(drawingSession); #endif drawingSession.Blend = previousBlend; } }
public static CanvasSpriteBatch CreateSpriteBatch(this CanvasDrawingSession session, bool pixelGraphics = false) { session.Units = CanvasUnits.Pixels; var spriteBatch = session.CreateSpriteBatch(CanvasSpriteSortMode.None, CanvasImageInterpolation.NearestNeighbor, CanvasSpriteOptions.ClampToSourceRect); return(spriteBatch); }
virtual protected void Stage_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { using (CanvasDrawingSession ds = args.DrawingSession) using (CanvasSpriteBatch SBatch = ds.CreateSpriteBatch(CanvasSpriteSortMode.Bitmap)) { lock ( Scenes ) { Scenes.ForEach(x => x.Draw(ds, SBatch, Textures)); } } }
// Draws all of the active particles. public void Draw(CanvasDrawingSession drawingSession, bool useSpriteBatch) { var previousBlend = drawingSession.Blend; drawingSession.Blend = blendState; if (useSpriteBatch) { using (var spriteBatch = drawingSession.CreateSpriteBatch()) { Draw(drawingSession, spriteBatch); } } else { Draw(drawingSession, null); } drawingSession.Blend = previousBlend; }
public override void Draw(CanvasDrawingSession session) { var size = new Size(50.0d, 50.0d); var sourceRect = new Rect(0.0d, 0.0d, 25.0d, 25.0d); using (session.CreateLayer(1.0f)) { using (var batch = session.CreateSpriteBatch(CanvasSpriteSortMode.Bitmap)) { for (var row = 0; row < 10; row++) { for (var column = 0; column < 10; column++) { var x = size.Width * column; var y = size.Height * row; batch.DrawFromSpriteSheet(bitmapBrush, new Rect(new Point(x, y), size), sourceRect); } } } } base.Draw(session); }
public SpriteBatchWrapper(CanvasDrawingSession drawingSession) { _spriteBatch = drawingSession.CreateSpriteBatch(CanvasSpriteSortMode.None, CanvasImageInterpolation.Linear, CanvasSpriteOptions.ClampToSourceRect); }