// Alternative entrypoint for use by AppIconGenerator. internal void DrawIcon(CanvasDrawingSession drawingSession, string text) { this.text = text; this.fontSize = 64; CreateFlameEffect(); SetupText(drawingSession); ConfigureEffect(new CanvasTimingInformation()); drawingSession.DrawImage(flamePosition); drawingSession.DrawImage(textCommandList); }
//int count; public void Draw(CanvasDrawingSession ds, Size sizeRender, float totalTimeSeconds) { //count++; //ds.DrawText(count.ToString(), new Vector2(10.0f, 10.0f), Colors.Red); SetupText(ds); ConfigureEffect(totalTimeSeconds); ds.DrawImage(composite, sizeRender.ToVector2() / 2); }
void ApplyBloomFilter(CanvasDrawingSession drawingSession) { // Configure effects to use the latest threshold, blur, and intensity settings. extractBrightAreas.RedSlope = extractBrightAreas.GreenSlope = extractBrightAreas.BlueSlope = 1 / (1 - BloomThreshold / 100); extractBrightAreas.RedOffset = extractBrightAreas.GreenOffset = extractBrightAreas.BlueOffset = -BloomThreshold / 100 / (1 - BloomThreshold / 100); blurBrightAreas.BlurAmount = BloomBlur; adjustBloomIntensity.RedSlope = adjustBloomIntensity.GreenSlope = adjustBloomIntensity.BlueSlope = BloomIntensity / 100; // Apply the bloom effect. drawingSession.DrawImage(bloomResult); }
// Draws all of the active particles. public void Draw(CanvasDrawingSession drawingSession) { var previousBlend = drawingSession.Blend; drawingSession.Blend = blendState; // Go through the particles in reverse order, so new ones are drawn underneath // older ones. This improves visual appearance of effects like smoke plume // where many particles are created at the same position over a period of time. for (int i = activeParticles.Count - 1; i >= 0; i--) { Particle particle = activeParticles[i]; // Normalized lifetime is a value from 0 to 1 and represents how far a particle // is through its life. 0 means it just started, .5 is half way through, and // 1.0 means it's just about to be finished. This value will be used to calculate // alpha and scale, to avoid having particles suddenly appear or disappear. float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime; // We want particles to fade in and fade out, so we'll calculate alpha to be // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is: // // (normalizedLifetime) * (1-normalizedLifetime) // (.5) * (1-.5) // .25 // // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4. float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime); // Make particles grow as they age. // They'll start at 75% of their size, and increase to 100% once they're finished. float scale = particle.Scale * (.75f + .25f * normalizedLifetime); // Compute a transform matrix for this particle. var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) * Matrix3x2.CreateScale(scale, bitmapCenter) * Matrix3x2.CreateTranslation(particle.Position - bitmapCenter); // Draw the particle. drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform)); } drawingSession.Blend = previousBlend; }
public void Draw(CanvasDrawingSession drawingSession) { // 保护原先画布的混合模式 var previousBlend = drawingSession.Blend; drawingSession.Blend = CanvasBlend.SourceOver; // Compute a transform matrix for this particle. if (canDraw) { var transform = Matrix3x2.CreateScale(scale.X, scale.Y, center) * Matrix3x2.CreateTranslation(position - center); if (blurFrame != 0) drawingSession.DrawImage(blur, new Rect(position.X - (bound.Width * scale.X) / 2, position.Y - (bound.Height * scale.Y) / 2, bound.Width * scale.X, bound.Height * scale.Y), bound, opacity); else drawingSession.DrawImage(tempSurface, 0f, 0f, bound, opacity, CanvasImageInterpolation.Linear, new Matrix4x4(transform)); } drawingSession.Blend = previousBlend; }
protected virtual void Draw(CanvasDrawingSession drawingSession #if WINDOWS_UWP , CanvasSpriteBatch spriteBatch #endif ) { // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好 for (int i = activeParticles.Count - 1; i >= 0; i--) { Particle particle = activeParticles[i]; // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时, // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放 //float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime; // We want particles to fade in and fade out, so we'll calculate alpha to be // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is: // // (normalizedLifetime) * (1-normalizedLifetime) // (.5) * (1-.5) // .25 // // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4. //float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime); // Make particles grow as they age. // They'll start at 75% of their size, and increase to 100% once they're finished. //float scale = particle.Scale * (.75f + .25f * normalizedLifetime); #if WINDOWS_UWP if (spriteBatch != null) { spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, 1/*alpha*/), bitmapCenter, particle.Rotation - 1.5708f, new Vector2(particle.ScaleX, particle.ScaleY/*scale*/), CanvasSpriteFlip.None); } else #endif { // Compute a transform matrix for this particle. var transform = Matrix3x2.CreateRotation(particle.Rotation - 1.5708f, bitmapCenter) * Matrix3x2.CreateScale(/*scale*/particle.ScaleX, particle.ScaleY, bitmapCenter) * Matrix3x2.CreateTranslation(particle.Position - bitmapCenter); // Draw the particle. drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, 1/*alpha*/, CanvasImageInterpolation.Linear, new Matrix4x4(transform)); } } }
public void Draw(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession) { if (currentThunder == null) { return; } // 保护原先画布的混合模式 var previousBlend = drawingSession.Blend; drawingSession.Blend = blendState; var builder = new CanvasPathBuilder(sender); builder.BeginFigure(0, 0); for (int i = 0; i < currentThunder.LifeLong; i++) { builder.AddLine(currentThunder.Path[i].X, currentThunder.Path[i].Y); } builder.EndFigure(CanvasFigureLoop.Open); builder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin); // Draw the particle. var path = CanvasGeometry.CreatePath(builder); var NormalizeLifeTime = currentThunder.TimeSinceStart / currentThunder.Duration; byte opacity = (byte)((NormalizeLifeTime - 1) * (NormalizeLifeTime - 1) * 255); CanvasCommandList cl = new CanvasCommandList(sender); using (CanvasDrawingSession clds = cl.CreateDrawingSession()) { clds.DrawGeometry(path, currentThunder.Position, Color.FromArgb((byte)(0.75f * opacity), 255, 255, 255), 6 * currentThunder.Luminace); } var lightAmount = 20.6f * currentThunder.Luminace * (NormalizeLifeTime - 1) * (NormalizeLifeTime - 1); blur.Source = cl; blur.BlurAmount = lightAmount; drawingSession.DrawImage(blur); drawingSession.DrawGeometry(path, currentThunder.Position, Color.FromArgb(opacity, 255, 240, 180), 2 * currentThunder.Luminace); drawingSession.Blend = previousBlend; if (NormalizeLifeTime > 1) { currentThunder = null; } }
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); }
public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height) { ++frameCounter; float opacity = (float)(Math.Sin(frameCounter * 0.05) + 1) / 2; DoTest(opacity, ignoreSource, premultipliedTarget[0]); DoTest(opacity, ignoreSource, ignoreTarget[0]); DoTest(opacity, premultipliedSource, premultipliedTarget[1]); DoTest(opacity, premultipliedSource, ignoreTarget[1]); float halfWidth = width / 2; var premultipliedToIgnoreLabel = MakeLabel(ds, "Draw Premultiplied to Ignore", halfWidth); var premultipliedToPremultipliedLabel = MakeLabel(ds, "Draw Premultiplied to Premultiplied", halfWidth); var ignoreToIgnoreLabel = MakeLabel(ds, "Draw Ignore to Ignore", halfWidth); var ignoreToPremultipliedLabel = MakeLabel(ds, "Draw Ignore to Premultiplied", halfWidth); var totalHeight = 64 * 8.0f; float middle = width / 2; float imageX = middle + 10; float textRight = middle - 10; float y = (height / 2) - (totalHeight / 2); float ydiff = 64.0f * 2.0f; ds.DrawImage(premultipliedTarget[0], imageX, y); ds.DrawTextLayout(premultipliedToPremultipliedLabel, 0, y, Colors.White); y += ydiff; ds.DrawImage(ignoreTarget[0], imageX, y); ds.DrawTextLayout(premultipliedToIgnoreLabel, 0, y, Colors.White); y += ydiff; ds.DrawImage(premultipliedTarget[1], imageX, y); ds.DrawTextLayout(ignoreToPremultipliedLabel, 0, y, Colors.White); y += ydiff; ds.DrawImage(ignoreTarget[1], imageX, y); ds.DrawTextLayout(ignoreToIgnoreLabel, 0, y, Colors.White); y += ydiff; }
private void DoUIElementsEffect(CanvasControl sender, CanvasDrawingSession ds) { foreach (var elm in _uielements) { var offset = (float)ExpandAmount / 2; using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { using (var canvasbmp = CanvasBitmap.CreateFromBytes(sender.Device, elm.Item1, elm.Item2, elm.Item3, Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized)) { clds.DrawImage(canvasbmp, 0, 0); } } _eg.Setup(cl, (float)GlowAmount, GlowColor); ds.DrawImage(_eg.Output, offset + (float)elm.Item4, offset + (float)elm.Item5); } } }
private void DoPathEffect(CanvasControl sender, CanvasDrawingSession ds ) { using (var thBuilder = new Microsoft.Graphics.Canvas.Geometry.CanvasPathBuilder(sender)) { var pthConverter = new PathToD2DPathGeometryConverter(); foreach(var path in _paths) { var offset = (float)ExpandAmount / 2; using (var cl = new CanvasCommandList(ds)) using (var pthGeo = pthConverter.parse(path, thBuilder)) { using (var clds = cl.CreateDrawingSession()) { clds.FillGeometry(pthGeo,0,0, GlowColor); } _eg.Setup(cl, (float)GlowAmount, GlowColor); ds.DrawImage(_eg.Output, offset, offset); ds.FillGeometry(pthGeo,offset, offset, ((SolidColorBrush)GlowFill).Color); } } } }
void DrawToOutput(PerDeviceResources resources, CanvasDrawingSession ds) { if (CurrentIntermediate == IntermediateMode.None) { // We can either draw directly to the output... DrawSourceGraphic(resources, ds, testOffset); } else { // Or go via an intermediate such as a rendertarget or image effect. var intermediateImage = WrapSourceWithIntermediateImage(resources, CurrentIntermediate); ds.DrawImage(intermediateImage, testOffset, testOffset); } resources.AddMessage("{0} (dpi: {1})", CurrentOutput, ds.Dpi); }
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"); } }
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; case DrawnContentType.Ellipse_Thick: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.DrawEllipse( point, radiusX, radiusY, NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Ellipse_Fill: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.FillEllipse( point, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.Circle_Fill: ds.FillCircle( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), 100, NextRandomColor()); break; case DrawnContentType.Dashed_Lines: DrawDashedLines(ds, NextRandomColor(), horizontalLimit, verticalLimit); break; case DrawnContentType.Text: var p = NextRandomPoint(horizontalLimit, verticalLimit); var x = (float)p.X; var y = (float)p.Y; var color = NextRandomColor(); ds.DrawLine(new Vector2(x, 0), new Vector2(x, verticalLimit), color); ds.DrawLine(new Vector2(0, y), new Vector2(horizontalLimit, y), color); ds.DrawText( "Centered", p.ToVector2(), color, new CanvasTextFormat() { FontSize = 18, VerticalAlignment = CanvasVerticalAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }); var r = NextRandomRect(horizontalLimit, verticalLimit); ds.DrawRectangle(r, color); ds.DrawText( m_quiteLongText, r, NextRandomColor(), new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 18, ParagraphAlignment = ParagraphAlignment.Justify, Options = CanvasDrawTextOptions.Clip }); break; case DrawnContentType.ImageBrush: if (m_bitmap_tiger != null) { m_imageBrush.Image = m_bitmap_tiger; m_imageBrush.ExtendX = (CanvasEdgeBehavior)(m_random.Next(3)); m_imageBrush.ExtendY = (CanvasEdgeBehavior)(m_random.Next(3)); ds.FillRectangle(new Rect(0, 0, horizontalLimit, verticalLimit), m_imageBrush); } else DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); break; case DrawnContentType.Test_Scene0_Default: GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Default); break; case DrawnContentType.Test_Scene0_Wireframe: GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe); break; case DrawnContentType.Test_Scene1_Default: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Default); break; case DrawnContentType.Test_Scene1_Randomized: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Randomized); break; case DrawnContentType.Test_Scene1_Wireframe: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe); break; default: System.Diagnostics.Debug.Assert(false); // Unexpected break; } }
public bool DisplayRegionMask(CanvasDrawingSession drawingSession, float zoomFactor, bool editInProgress) { if (!IsEnabled || !IsEditingRegion || !ShowRegion || regionMask == null) return false; if (editInProgress && RegionSelectionOperation == SelectionOperation.Replace) return false; drawingSession.Blend = CanvasBlend.SourceOver; if (!editInProgress) { // Gray out everything outside the region. var mask = new ColorMatrixEffect { Source = GetRegionMask(), ColorMatrix = new Matrix5x4 { // Set RGB = gray. M51 = 0.5f, M52 = 0.5f, M53 = 0.5f, // Invert and scale the mask alpha. M44 = -0.75f, M54 = 0.75f, } }; drawingSession.DrawImage(mask); } // Magenta region border. var border = GetSelectionBorder(regionMask, zoomFactor); drawingSession.DrawImage(border); return true; }
public void DisplayRegionEditInProgress(CanvasDrawingSession drawingSession, List<Vector2> points, float zoomFactor) { if (RegionSelectionMode == SelectionMode.MagicWand) { // Display a magic wand selection. var mask = GetMagicWandMask(points, zoomFactor); var border = GetSelectionBorder(mask, zoomFactor); drawingSession.Blend = CanvasBlend.Add; drawingSession.DrawImage(mask, Vector2.Zero, SourceBitmap.Bounds, 0.25f); drawingSession.Blend = CanvasBlend.SourceOver; drawingSession.DrawImage(border); } else { // Display a geometric shape selection. var geometry = GetSelectionGeometry(drawingSession, points); drawingSession.Blend = CanvasBlend.Add; drawingSession.FillGeometry(geometry, Color.FromArgb(0x20, 0xFF, 0xFF, 0xFF)); drawingSession.Blend = CanvasBlend.SourceOver; drawingSession.DrawGeometry(geometry, Colors.Magenta, 1f / zoomFactor); } }
protected override void Draw(CanvasDrawingSession drawingSession #if WINDOWS_UWP , CanvasSpriteBatch spriteBatch #endif ) { // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好 for (int i = ActiveParticles.Count - 1; i >= 0; i--) { Particle particle = ActiveParticles[i]; // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时, // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放 float normalizedLifetime = particle.TimeSinceStart / 4; if (normalizedLifetime > 1) { normalizedLifetime = 1; } // We want particles to fade in and fade out, so we'll calculate alpha to be // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is: // // (normalizedLifetime) * (1-normalizedLifetime) // (.5) * (1-.5) // .25 // // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4. float alpha = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, normalizedLifetime); var x = particle.ScaleX; var y = particle.ScaleY; // Make particles grow as they age. // They'll start at 75% of their size, and increase to 100% once they're finished. if (isImmersive) { alpha *= 0.8f; x *= 1.2f; y *= 1.2f; } #if WINDOWS_UWP if (spriteBatch != null) { spriteBatch.Draw(smokeSurfaces[particle.Key], particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter, particle.Rotation, new Vector2(x, y), CanvasSpriteFlip.None); } else #endif { // Compute a transform matrix for this particle. var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) * Matrix3x2.CreateScale(x, y, bitmapCenter) * Matrix3x2.CreateTranslation(particle.Position - bitmapCenter); // Draw the particle. drawingSession.DrawImage(smokeSurfaces[particle.Key], 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform)); } } }
private void DoEffect(CanvasDrawingSession ds, Size size, float amount, Windows.UI.Color glowColor, Windows.UI.Color fillColor, double expandAmount) { var offset = (float)expandAmount / 2; //using (var textLayout = CreateTextLayout(ds, size)) using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { clds.FillRectangle(0, 0, (float)size.Width, (float)size.Height, glowColor); } glowEffectGraph.Setup(cl, amount); ds.DrawImage(glowEffectGraph.Output, offset, offset); ds.FillRectangle(offset, offset, (float)size.Width, (float)size.Height, fillColor); } }
private void DrawSprite(CanvasDrawingSession g, object o, Vector2 position) { var visualHint = o as IVisualHint; var canvasPosition = _coords.GameToCanvasPoint(position); var targetRect = new F.Rect(canvasPosition.X, canvasPosition.Y, CurrentZoomLevel * _coords.DipsPerUnit, CurrentZoomLevel * _coords.DipsPerUnit); var sourceRect = _spriteSheet[visualHint?.VisualKey]; var orientation = visualHint?.VisualOrientation ?? Point.Zero; if (orientation.IsDirection) { var rotation = _radiansForDirection[orientation]; var m = Matrix4x4.CreateRotationZ(rotation, new Vector3(canvasPosition.X + (CurrentZoomLevel * _coords.DipsPerUnit) / 2, canvasPosition.Y + (CurrentZoomLevel * _coords.DipsPerUnit) / 2, 0)); g.DrawImage(_spriteSheet.Image, targetRect, sourceRect, 1, CanvasImageInterpolation.Linear, m); } else { g.DrawImage(_spriteSheet.Image, targetRect, sourceRect); } }
private async void DoStreamsEffect(CanvasControl sender, CanvasDrawingSession ds) { foreach (var stream in _streams) { var offset = (float)ExpandAmount / 2; using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { stream.Seek(0); var canvasbmp = await CanvasBitmap.LoadAsync(sender, stream); clds.DrawImage(canvasbmp, 0, 0); } _eg.Setup(cl, (float)GlowAmount, GlowColor); ds.DrawImage(_eg.Output, offset, offset); } } }
private void DoEffect(CanvasDrawingSession ds, Size size, float amount) { size.Width = size.Width - ExpandAmount; size.Height = size.Height - ExpandAmount; var offset = (float)(ExpandAmount / 2); using (var textLayout = CreateTextLayout(ds, size)) using (var textCommandList = new CanvasCommandList(ds)) { using (var textDs = textCommandList.CreateDrawingSession()) { textDs.DrawTextLayout(textLayout, 0, 0, GlowColor); } glowEffectGraph.Setup(textCommandList, amount); ds.DrawImage(glowEffectGraph.Output, offset, offset); ds.DrawTextLayout(textLayout, offset, offset, TextColor); } }
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 ds, int frameCounter, float width, float height) { Size sz = sourceBitmap.Size; double sourceSizeScale = (Math.Sin(frameCounter * 0.03) * 0.3) + 0.7; Point center = new Point(Math.Sin(frameCounter * 0.02), (Math.Cos(frameCounter * 0.01))); center.X *= (1 - sourceSizeScale) * sz.Width * 0.5; center.Y *= (1 - sourceSizeScale) * sz.Height * 0.5; center.X += sz.Width * 0.5; center.Y += sz.Height * 0.5; Rect sourceRect = new Rect( center.X - sz.Width * sourceSizeScale * 0.5, center.Y - sz.Height * sourceSizeScale * 0.5, sz.Width * sourceSizeScale, sz.Height * sourceSizeScale); UpdateSourceRectRT(sourceRect); var format = new CanvasTextFormat() { FontSize = 14, HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Center, WordWrapping = CanvasWordWrapping.Wrap }; float y = 0; float labelX = width / 2 - 5; float imageX = width / 2 + 5; float entryHeight = (float)sourceBitmap.Bounds.Height; float margin = 14; Rect labelRect = new Rect(0, y, labelX, entryHeight); ds.DrawText(string.Format("Source image {0} DPI", sourceBitmap.Dpi), labelRect, Colors.White, format); ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern); ds.DrawImage(showSourceRectRT, imageX, y, showSourceRectRT.Bounds, 1, CanvasImageInterpolation.NearestNeighbor); y += entryHeight + margin; labelRect.Y = y; ds.DrawText("D2D DrawBitmap (emulated dest rect)", labelRect, Colors.White, format); ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern); ds.DrawImage(sourceBitmap, imageX, y, sourceRect); y += (float)sourceBitmap.Bounds.Height + 14; labelRect.Y = y; ds.DrawText("D2D DrawImage", labelRect, Colors.White, format); ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern); ds.DrawImage(sourceEffect, imageX, y, sourceRect); }
private bool Trail_Smudge(CanvasDrawingSession context, Drop drop) { var y = drop.Y - drop.R - 3; var x = drop.X - drop.R / 2 + (random.NextDouble() * 2); if (y < 0 || x < 0) { return false; } context.DrawImage(img, new Rect(x, y, drop.R, 2), new Rect(x / ImgScalefactor, y / ImgScalefactor, drop.R / ImgScalefactor, 2 / ImgScalefactor), 1); return true; }
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; }
private bool Reflection_Miniature(CanvasDrawingSession context, Drop drop) { var sx = Math.Max((drop.X / ImgScalefactor - reflectionDropMappingWidth), 0); var sy = Math.Max((drop.Y / ImgScalefactor - reflectionDropMappingHeight), 0); var sw = PositiveMin(reflectionDropMappingWidth * 2, width/ImgScalefactor - sx); var sh = PositiveMin(reflectionDropMappingHeight * 2, height / ImgScalefactor - sy); var dx = Math.Max(drop.X - 1.1 * drop.R, 0); var dy = Math.Max(drop.Y - 1.1 * drop.R, 0); context.DrawImage(img, new Rect(dx, dy, drop.R * 2, drop.R * 2), new Rect(sx, sy, sw, sh)); return true; }
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 }); } }
static void DrawSecondsText(CanvasDrawingSession ds, Vector2 pos, int seconds) { // The text is drawn via a command list so we can use DrawImage to specify a difference CanvasComposite mode. using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { clds.DrawText(seconds.ToString(), Vector2.Zero, Colors.White, textFormat); } Rect textBounds = cl.GetBounds(ds); var offset = new Vector2((float)textBounds.Left, (float)textBounds.Top); ds.DrawImage(cl, pos + offset, cl.GetBounds(ds), 1, CanvasImageInterpolation.NearestNeighbor, CanvasComposite.MaskInvert); } }
private void DrawPage(CanvasPrintDocument sender, CanvasDrawingSession ds, uint pageNumber, Rect imageableRect) { var cellAcross = new Vector2(cellSize.X, 0); var cellDown = new Vector2(0, cellSize.Y); var totalSize = cellAcross * columns + cellDown * rows; Vector2 topLeft = (pageSize - totalSize) / 2; int bitmapIndex = ((int)pageNumber - 1) * bitmapsPerPage; var labelFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 12, VerticalAlignment = CanvasVerticalAlignment.Bottom, HorizontalAlignment = CanvasHorizontalAlignment.Left }; var numberFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 18, VerticalAlignment = CanvasVerticalAlignment.Top, HorizontalAlignment = CanvasHorizontalAlignment.Left }; var pageNumberFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 10, VerticalAlignment = CanvasVerticalAlignment.Bottom, HorizontalAlignment = CanvasHorizontalAlignment.Center }; var titleFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 24, VerticalAlignment = CanvasVerticalAlignment.Top, HorizontalAlignment = CanvasHorizontalAlignment.Left }; if (pageNumber == 1) ds.DrawText("Win2D Printing Example", imageableRect, Colors.Black, titleFormat); ds.DrawText(string.Format("Page {0} / {1}", pageNumber, pageCount), imageableRect, Colors.Black, pageNumberFormat); DrawGrid(ds, cellAcross, cellDown, topLeft); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { var cellTopLeft = topLeft + (cellAcross * column) + (cellDown * row); var paddedTopLeft = cellTopLeft + textPadding / 2; var paddedSize = cellSize - textPadding; var bitmapInfo = bitmaps[bitmapIndex % bitmaps.Count]; // Center the bitmap in the cell var bitmapPos = cellTopLeft + (cellSize - bitmapInfo.Bitmap.Size.ToVector2()) / 2; ds.DrawImage(bitmapInfo.Bitmap, bitmapPos); using (var labelLayout = new CanvasTextLayout(sender, bitmapInfo.Name, labelFormat, paddedSize.X, paddedSize.Y)) using (var numberLayout = new CanvasTextLayout(sender, (bitmapIndex + 1).ToString(), numberFormat, paddedSize.X, paddedSize.Y)) { DrawTextOverWhiteRectangle(ds, paddedTopLeft, labelLayout); DrawTextOverWhiteRectangle(ds, paddedTopLeft, numberLayout); } bitmapIndex++; } } }
public void Draw(CanvasDrawingSession session) { session.DrawImage(displacement,new Vector2(X, Y)); //session.DrawImage((ICanvasImage)displacement.Source, new Vector2(X, Y)); }